AWK- an advanced fileter
aho,weinberger and kernighan
gawk in linux
awk options 'selection criteria {action}' files
printing is the default action of awk
awk '/rahul/' 1.txt
awk '/rahul/{print}' 1.txt
both are same and will print the lines containing rahul
awk -F" " '/rahul/{print $2,$3}' 1.txt
it will print 2nd and 3rd parameter in all lines containing rahul delimited by a space
awk -F " " 'NR==1,NR==10{print $1,$2,$3}' 1.txt
it will print first 10 lines ;its 1st , 2nd and third parameters delimited by space.
awk 'BEGIN{FS=" "}
=> NF!=6{
=> print "record number",NR,"has",NF,"fields"}' 1.txt
using built in variables
NR no of records
FS field separator
OFS output fiels separator
NF Number of fields in current line
FILENAME current input file
ARGC no of arguments in current line
ARGV List of arguments
using functions
awk -F" " 'length($2) < 1' 1.txt
those which have short second parameter
No comments:
Post a Comment