Bash 5 reference · Text and System Tools
awk (Linux command)
Process text by fields: print and filter columns, compute sums and group totals, with a small built-in language.
Bash 5
Syntax
awk [-F SEP] [-v VAR=VAL] 'PATTERN { ACTION } END { ... }' [FILE...]
Parameters
| Parameter | Description |
|---|---|
$1, $NF, $0 |
First field, last field, whole line. |
-F, |
Field separator. |
NR / NF |
Line number / number of fields. |
END { } |
Runs after the last line. |
Examples
printf 'ana DE 12\nben US 3\nchen DE 7\n' | awk '$3 > 5 { print $1 }'
Output
ana chen
Run this on your computer — see “Get Started” for setup.
printf 'north 120\nsouth 80\nnorth 40\n' | awk '{ t[$1] += $2 } END { for (r in t) print r, t[r] }' | sort
Output
north 160 south 80
Run this on your computer — see “Get Started” for setup.
Related
cut· Extract columns from each line by delimiter and field number, or by character positions.sort· Sort lines alphabetically, numerically, in reverse, by a key column, or with human-readable sizes; -u removes duplicates.- Bash awk: Process Columns · tutorial