Gawk/Testing-field-creation

From Get docs

4.8 Checking How gawk Is Splitting Records

As we’ve seen, gawk provides three independent methods to split input records into fields. The mechanism used is based on which of the three variables—FS, FIELDWIDTHS, or FPAT—was last assigned to. In addition, an API input parser may choose to override the record parsing mechanism; please refer to Customized Input Parsers for further information about this feature.

To restore normal field splitting after using FIELDWIDTHS and/or FPAT, simply assign a value to FS. You can use ‘FS = FS’ to do this, without having to know the current value of FS.

In order to tell which kind of field splitting is in effect, use PROCINFO["FS"] (see section Built-in Variables That Convey Information). The value is "FS" if regular field splitting is being used, "FIELDWIDTHS" if fixed-width field splitting is being used, or "FPAT" if content-based field splitting is being used:

if (PROCINFO["FS"] == "FS")
    regular field splitting …
else if (PROCINFO["FS"] == "FIELDWIDTHS")
    fixed-width field splitting …
else if (PROCINFO["FS"] == "FPAT")
    content-based field splitting …
else
    API input parser field splitting … (advanced feature)

This information is useful when writing a function that needs to temporarily change FS or FIELDWIDTHS, read some records, and then restore the original settings (see section Reading the User Database for an example of such a function).