awk Command Examples

A versatile programming language for working on files. More information: https://github.com/onetrueawk/awk.

awk '{print $5}' {{path/to/file}}

awk '/{{foo}}/ {print $2}' {{path/to/file}}

awk -F ',' '{print $NF}' {{path/to/file}}

awk '{s+=$1} END {print s}' {{path/to/file}}

awk 'NR%3==1' {{path/to/file}}

awk '{if ($1 == "foo") print "Exact match foo"; else if ($1 ~ "bar") print "Partial match bar"; else print "Baz"}' {{path/to/file}}

awk '($10 >= {{min_value}} && $10 <= {{max_value}})'

awk 'BEGIN {FS=":";printf "%-20s %6s %25s\n", "Name", "UID", "Shell"} $4 >= 1000 {printf "%-20s %6d %25s\n", $1, $4, $7}' /etc/passwd