awk(1)
awk [opt] program [input]
-F <sepstr> field separator string (can be regex)
program awk program
input file or stdin if not file given
Input processing
Input is processed in two stages:
- Splitting input into a sequence of
records
. By default split atnewline
character, but can be changed via the builtinRS
variable. - Splitting a
record
intofields
. By default strings withoutwhitespace
, but can be changed via the builtin variableFS
or command line option-F
.
Field are accessed as follows:
$0
wholerecord
$1
field one$2
field two- ...
Program
An awk
program is composed of pairs of the form:
pattern { action }
The program is run against each record
in the input stream. If a pattern
matches a record
the corresponding action
is executed and can access the
fields
.
INPUT
|
v
record ----> ∀ pattern matched
| |
v v
fields ----> run associated action