Thursday, 25 April 2013

Unix Awk Script: Print all fields except last two fields of a file

Lets take an example file as follows:

$ cat file
A    B    C    D    E
A    B    C    D    E

If you want to print all fields except last two fields , it can be done using "awk" as follows: 

$ awk '{$NF="";$(NF-1)="";print $0}' file
A B C   
A B C                                                                                                  

No comments:

Post a Comment