awk made easy

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, 0isthewholerow<br/><br/>ifitonlynecessarytoprintcolumnsofafileitiseasiertousecut:<br/><br/>namea|cutd""f1,3,11,12<br/><br/>d:ord""isthedelimiter<br/>f1,3arethefieldstobedisplayed<br/>otheroptions:sdoesntshowlineswithoutdelimiters,complementisselfesplicative<br/>conditiononaspecificfield:<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