BEGIN/END blocks awk
Run code before and after processing all lines
awk 'BEGIN{print "Start"} {lines++} END{print lines" lines processed"}' file.txt
more awk
all 15 commands →
Two-file join on key
awk 'NR==FNR{a[$1]=$2; next} $1 in a {print $0, a[$1]}' lookup.txt data.txt
Print specific column
awk '{print $3}' file.txt
Custom field separator
awk -F: '{print $1, $3}' /etc/passwd
Filter rows by pattern
awk '/ERROR/ {print NR": "$0}' app.log
Sum a column
awk '{sum += $4} END {print sum}' access.log