|
|
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
field1
When the field separator is a tab,
however,
leading blanks are
not
discarded.
The field separator can be set to any extended regular expression by assigning a value to the built-in variable FS. For example,
BEGIN { FS = ",[\t]*|([\t]+)" }
makes into field separators every string consisting of a comma followed by blanks or tabs and every string of blanks or tabs with no comma. FS can also be set on the command line with the -F argument:
$ awk -F'(,[ \t]behaves the same as the previous example. Regular expressions used as field separators match the leftmost longest occurrences (as in sub), but do not match null strings.)|([ \t]+)' '. . .'<<Return>>