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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

awk [-F SEP] [-v VAR=VAL] 'PATTERN { ACTION } END { ... }' [FILE...]

Parameters

ParameterDescription
$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

Filter by a column
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.

Group and sum
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.

Was this page helpful?