FS is one of several user-modifiable built in variables in the awk programming language.

FS is the input field separator. When awk reads data from standard input, it separates each "record" (by default, one line of text; see RS) into "fields". The value of FS determines how that's done.

By default, fields are separated by whitespace, any amount of it (/[ \t]+/, if you dig regular expressions).

For example, the following record:

    foo   bar baz

...will be split up into three fields, "foo", "bar", and "baz". Any series of spaces and/or tabs is considered to be the boundary between one field and the next. The alert reader will notice that it's impossible to have an empty field if you're doing it this way.

This default behavior is specified by a special case value for FS, a single space: " ". Any other single-character value assigned to FS will be taken as a literal string, and the field separator will be exactly that, no more and no less.

Assume that we've set FS to ",", for example:

    foo,,,bar,baz

Here, there's none of this "series" stuff; the fields we have are as follows: "foo", "", "", "bar", and "baz". Now we can have empty fields, if any turn up in the input stream.

Both kinds of behavior have their uses.

There's a third mode of operation here: If the string you assign to FS is more than one character long, the awk interpreter assumes that it's a regular expression, in which case fields are separated by any series of characters that happens to match the regex.

In all of these cases, the content of the "field separator" itself is eaten and discarded by awk when the fields are separated.




Reference: The GNU Awk User's Guide

My O'Reilly awk book is at home. The gawk manual seems to think that all of the above is standard rather than gawk-specific, but those who trust manuals are doomed to consult them, so take that with a grain of salt.