Posts

Showing posts from February, 2012

AWK

AWK Structure pattern {action} BEGIN and END patterns in the AWK BEGIN { print “BEGIN” } { print } END   { print “END”  } # cat textfile.txt  Ashish 123 Ashi     456 Ash      789 A          000 # awk '{print $1}' textfile.txt  Ashish Ashi Ash A # awk '{print $2}' textfile.txt  123 456 789 000 # awk '{print $2,$1}' textfile.txt  123 Ashish 456 Ashi 789 Ash 000 A If the file is seperated with some delimeter, then we make use of -F for awk. In the below example, the input file is using the pipe ( | ) as delimiter. # cat textfile.txt  Ashish|123 Ashi|456 Ash|789 A|000 Ashish|007 # awk -F\| '{print $1}' textfile.txt  Ashish Ashi Ash A Ashish # awk -F\| '{print $2}' textfile.txt  123 456 789 000 007 # awk -F\| '{print $2,$1}' textfile.txt  123 Ashish 456 Ashi 789 Ash 000 A 007 Ashish # awk...