Tools
Awk
Extract fields and summarize text with small, readable programs.
Updated Official documentation ↗
Fields and separators
awk '{print $1}' file.txtPrint the first whitespace-separated fieldawk -F, '{print $2}' data.csvSplit simple comma-delimited text; not a full CSV parserawk '{print NR, $0}' file.txtPrefix each record with its numberawk '{print NF}' file.txtCount fields on each recordSelect records
awk '/error/' app.logPrint matching recordsawk 'NR > 1' data.txtSkip the first recordawk '$3 > 100' data.txtSelect by a numeric fieldawk 'length($0) > 80' file.txtFind long linesAggregate
awk '{total += $2} END {print total}' data.txtSum the second fieldawk 'END {print NR}' file.txtCount recordsawk '{count[$1]++} END {for (k in count) print k, count[k]}' data.txtCount records by first fieldawk 'BEGIN {OFS=","} {print $1,$2}' data.txtSet the output field separator