|
|
With the default setting of the field separator FS, input fields are separated by blanks or tabs, and leading blanks are discarded, so each of these lines has the same first field:
field1 field2 field1 field1When the field separator is a tab, however, leading blanks are not discarded.
The field separator can be set to any regular expression by assigning a value to the built-in variable FS. For example, the following sets it to any or all of comma, space and tab:
BEGIN { FS = "([, \\t])" }You can also set FS on the command line with the -F argument. For example, this behaves the same as the previous example:
awk -F'([, \\t])'Regular expressions used as field separators match the leftmost longest occurrences (as in the sub function), but they do not match null strings.