Recommended awk tutorials

The Grymoire’s tutorial on AWK
The Grymoire - Tutorial on the AWK program language.

Samples

  • awk -f awk-script.awk input-file.txt
  • awk 'BEGIN {print "hello"} {print $0} END {print "end"}' input-file.txt
  • cat input-file.txt | awk -f awk-script.awk
  • awk -v awk_var=$my_bash_var 'length { print awk_var }' input-file.txt. Show $my_bash_var on non-empty lines.
  • Followings are same
{if ($0 ~ /special/) {print}}
$0 ~ /special/ {print}
/special/ {print $0}
  • Combine multiple conditions
($0 ~ /whole/) || (($1 ~ /part1/) && ($2 ~ /part2/)) {print}