DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Using 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 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.
Next topic: Multiline records
Previous topic: Files and pipes

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003