There are times when you may want to examine each character
of a record separately. In gawk
, this is easy to do, you
simply assign the null string (""
) to FS
. In this case,
each individual character in the record will become a separate field.
Here is an example:
$ echo a b | gawk 'BEGIN { FS = "" } > { > for (i = 1; i <= NF; i = i + 1) > print "Field", i, "is", $i > }' -| Field 1 is a -| Field 2 is -| Field 3 is b
Traditionally, the behavior for FS
equal to ""
was not defined.
In this case, Unix awk
would simply treat the entire record
as only having one field (d.c.). In compatibility mode
(see section Command Line Options),
if FS
is the null string, then gawk
will also
behave this way.
Go to the first, previous, next, last section, table of contents.