awk advanced (advanced)

Advanced awk: multi-condition processing, BEGIN/END blocks, associative arrays.

low risk

interactive breakdown — edit the command and press Explain
$ 
What it does

awk is a full programming language embedded in the shell pipeline. Beyond simple field printing, it supports BEGIN/END blocks for pre/post processing, associative arrays for aggregation, conditional logic, and arithmetic — replacing Python for many data processing tasks.

Common flags
FlagMeaning
-FSet field separator
-vSet variable before processing begins
-fRead awk program from file
Examples
awk 'BEGIN{sum=0} {sum+=$5} END{print "Total:",sum}' access.logSum a column across all lines · explain & risk-check →
awk -F: '$3>=1000{print $1,$3}' /etc/passwdPrint users with UID >= 1000 (non-system users) · explain & risk-check →
awk '{count[$9]++} END{for(code in count) print code, count[code]}' access.log | sort -k2 -rnCount HTTP status codes in access log · explain & risk-check →
awk 'NR%2==0' file.txtPrint even-numbered lines · explain & risk-check →
awk '/START/,/END/' logfilePrint lines between two patterns · explain & risk-check →
Pro tip

Use `awk '{count[$1]++} END{for(k in count) print count[k], k}' | sort -rn` for instant frequency analysis of any column — replaces sort|uniq -c for multi-field grouping.

Related
sed cut jq
Open the full explainer →More in Text Processing

Reference text is hand-written and may be incomplete — check man awk for your version. Test destructive commands on a non-production system first.