2013年4月14日 星期日

[awk] Print only specific field

Ex1:

$cat employee.txt
100  Thomas  Manager    Sales       $5,000
200  Jason   Developer  Technology  $5,500
300  Sanjay  Sysadmin   Technology  $7,000
400  Nisha   Manager    Marketing   $9,500
500  Randy   DBA        Technology  $6,000

$ awk '{print $2,$5;}' employee.txt
Thomas $5,000
Jason $5,500
Sanjay $7,000
Nisha $9,500
Randy $6,000

$ awk '{print $2,$NF;}' employee.txt
Thomas $5,000
Jason $5,500
Sanjay $7,000
Nisha $9,500
Randy $6,000


$NF represents last field


Ex2 :

$cat employee.txt
100/Thomas/Manager/Sales/$5,000

$ awk -F"/" '{print $2,$NF;}' employee.txt

Reference :

Related Posts:

0 意見:

張貼留言