awk
$ awk –F'[ :\t]' '{print $1, $2, $3}' people.txt---------------------------- $ awk '{print NR, $1, $2, $4}' people.txtThe output will be:
1 Bill Thomas 08/9/1968 2 Fred Martin 22/7/1982 3 Julie Moore 25/2/1978 4 Marie Jones 05/8/1972 5 Tom Walker 14/1/1977-----------------------------------------$ cat people.txt | awk '$3 > 6500 {print $1, $2}'
===========================Bill Thomas 8000 08/9/1968 Fred Martin 6500 22/7/1982 Julie Moore 4500 25/2/1978 Marie Jones 6000 05/8/1972 Tom Walker 7000 14/1/1977 $ awk '{if ($3 > 7000) { print "person with salary more than 7000 is \n", $1, " " , $2;}}' people.txtThe output is as follows:
person with salary more than 7000 is Bill ThomasAn example of the awk command with the for loop is as follows:
$ awk '{ for( i = 1; i <= NF; i++) print NF, $i }' people.txt
---------------------------------------------------
$ cat people.txt
=============================$ awk '{ i = 1; while ( i <= NF ) { print NF, $i ; i++ } }' people.txt================================$ cat awk_script BEGIN {do { ++x
print x } while ( x <= 4 )} $ awk -f awk_script
Comments
Post a Comment