DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with awk

Input separators

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]*)|([ \t]+)' '. . .'<<Return>>
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.
Next topic: Multi-line records
Previous topic: Files and pipes

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005