TECH SOLUTIONS

Click here to edit subtitle

Forums

Post Reply
Forum Home > Unix Learnings > Awk: Print all fields except last two fields of a file

Sourav Gulati
Site Owner
Posts: 83

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  

 

 


 

 

 

--


January 30, 2013 at 5:38 AM Flag Quote & Reply

You must login to post.