Text Processing // Data Extraction
awk
A full programming language for transforming columnar text.
$ awk 'PATTERN { ACTION }' [FILE...]
Key Concepts
$1 $2 …Fields (columns), split by FS (default: whitespace) -F ":"Set field separator to colon (or any char) NRCurrent line number (Number of Records) NFNumber of fields on the current line BEGIN{}Run before any input is read END{}Run after all input is processed
Examples
$ awk '$2 > 80 {print $1, "passed"}' scores.txt
alice passed
carla passed
Filter rows by numeric field value — awk is a row-level if/print engine
$ awk -F: '{print $1, $3}' /etc/passwd
root 0
daemon 1
jirie 1000
postgres 113
Extract username + UID — colon-delimited, no cut needed
$ awk 'NR>1 {sum+=$3} END {print "avg:", sum/(NR-1)}' data.txt
avg: 84.3
Skip header row, accumulate, compute — all in one pass