awk made easy

linux
Published

September 22, 2006

awk ’/REGEX/ {print NR “ $9” $4”_“\(5 ;}' file.txt </strong> <br/> supports extended REGEX like perl ( e.g. [:blank:] Space or tab characters ) <br/> NR is line number <br/> NF Number of fields <br/>\)n is the column to be printed, \(0 is the whole row <br/> <br/> if it only necessary to print columns of a file it is easier to use cut: <br/> <br/> name -a | cut -d" " -f1,3,11,12 <br/> <br/> -d: or -d" " is the delimiter <br/> -f1,3 are the fields to be displayed <br/> other options: -s doesnt show lines without delimiters, --complement is selfesplicative <br/> condition on a specific field: <br/>\)<field> ~ /<string>/ Search for string in specified field.

you can use awk also in pipes:
ll | awk ‘NR!=1 {s+=$5} END {print “Average:” s/(NR-1)}’
END to process al file and then print results

tutorial on using awk from the command line:
http://www.vectorsite.net/tsawk_3.html#m1