As each input line is read,
gawk splits the line into
fields, using the value of the
FS variable as the field
FS is a single character, fields are separated by
that character. Otherwise,
FS is expected to be a full regular
expression. In the special case that
FS is a single space,
fields are separated by runs of spaces, tabs and/or newlines.(28)
FS is the null string (
""), then each individual
character in the record becomes a separate field.
Note that the value
IGNORECASE (see section Case-sensitivity in Matching)
also affects how fields are split when
FS is a regular expression.
Each field in the input line may be referenced by its position,
$2, and so on.
$0 is the whole line. The value of a field may
be assigned to as well. Field numbers need not be constants:
n = 5 print $n
prints the fifth field in the input line. The variable
NF is set to
the total number of fields in the input line.
References to non-existent fields (i.e. fields after
the null string. However, assigning to a non-existent field (e.g.,
$(NF+2) = 5) increases the value of
NF, creates any
intervening fields with the null string as their value, and causes the
$0 to be recomputed, with the fields being separated by
the value of
NF causes the values of fields past the new value to
be lost, and the value of
$0 to be recomputed, with the fields being
separated by the value of
See section Reading Input Files.
Go to the first, previous, next, last section, table of contents.