Pattern Searching and Processing

awk

Batch editor may be used as a filter in one of 2 ways:

awk [-Fc] -f program-file [ file-list ]

awk program [ file-list ]

awk programs

A program contains one or more lines with the format:

pattern { action }

The awk utility works as follows:

Patterns

Patterns may match either specified fields, variable values, or the entire input line.

Variables

User-specified variables are created and initialized when you use them.

Other variables available for your use:

NR record (line) number of current record
$0 the current record (input line)
NF number of fields in the current record
$1 - $n specific fields in the current record
FS input field separator (default: space or tab)
OFS output field separator (default: space)
RS input record separator (default: newline)
ORS output record separator (default: newline)
FILENAME name of current input file

Printing

print may be specified explicitly or implied (if no action is specified)

Actions

In addition to printing, awk support several other actions.