String processing with awk

The awk program is more powerful than even sed. The language for awk is based on the C programming language. The basic usage is:

awk 'program' filenames..

but the program is a series of patterns and actions to take on lines matching those patterns.

pattern { action }
pattern { action }
$\ldots$

Here we will touch on some simple uses.

The awk program splits each line into fields, that is, strings of non-blank characters separated by blanks or tabs. The fields are called $1, $2, ..., $NF. The variable $0 represents the whole line.

awk has arrays, full programming language statements and much more. Please see the book on AWK [2] to learn more.