| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
7.5.1 Built-in Variables That Control awk
The following is an alphabetical list of variables that you can change to
control how awk does certain things. The variables that are
specific to gawk are marked with a pound sign (‘#’).
-
BINMODE # On non-POSIX systems, this variable specifies use of binary mode for all I/O. Numeric values of one, two, or three specify that input files, output files, or all files, respectively, should use binary I/O. A numeric value less than zero is treated as zero, and a numeric value greater than three is treated as three. Alternatively, string values of
"r"or"w"specify that input files and output files, respectively, should use binary I/O. A string value of"rw"or"wr"indicates that all files should use binary I/O. Any other string value is treated the same as"rw", but causesgawkto generate a warning message.BINMODEis described in more detail in Usinggawkon PC Operating Systems.This variable is a
gawkextension. In otherawkimplementations (exceptmawk, see section Other Freely AvailableawkImplementations), or ifgawkis in compatibility mode (see section Command-Line Options), it is not special.-
CONVFMT This string controls conversion of numbers to strings (see section Conversion of Strings and Numbers). It works by being passed, in effect, as the first argument to the
sprintf()function (see section String-Manipulation Functions). Its default value is"%.6g".CONVFMTwas introduced by the POSIX standard.-
FIELDWIDTHS # This is a space-separated list of columns that tells
gawkhow to split input with fixed columnar boundaries. Assigning a value toFIELDWIDTHSoverrides the use ofFSandFPATfor field splitting. See section Reading Fixed-Width Data, for more information.If
gawkis in compatibility mode (see section Command-Line Options), thenFIELDWIDTHShas no special meaning, and field-splitting operations occur based exclusively on the value ofFS.-
FPAT # This is a regular expression (as a string) that tells
gawkto create the fields based on text that matches the regular expression. Assigning a value toFPAToverrides the use ofFSandFIELDWIDTHSfor field splitting. See section Defining Fields By Content, for more information.If
gawkis in compatibility mode (see section Command-Line Options), thenFPAThas no special meaning, and field-splitting operations occur based exclusively on the value ofFS.-
FS This is the input field separator (see section Specifying How Fields Are Separated). The value is a single-character string or a multi-character regular expression that matches the separations between fields in an input record. If the value is the null string (
""), then each character in the record becomes a separate field. (This behavior is agawkextension. POSIXawkdoes not specify the behavior whenFSis the null string. Nonetheless, some other versions ofawkalso treat""specially.)The default value is
" ", a string consisting of a single space. As a special exception, this value means that any sequence of spaces, TABs, and/or newlines is a single separator.(35) It also causes spaces, TABs, and newlines at the beginning and end of a record to be ignored.You can set the value of
FSon the command line using the ‘-F’ option:awk -F, 'program' input-files
If
gawkis usingFIELDWIDTHSorFPATfor field splitting, assigning a value toFScausesgawkto return to the normal,FS-based field splitting. An easy way to do this is to simply say ‘FS = FS’, perhaps with an explanatory comment.-
IGNORECASE # If
IGNORECASEis nonzero or non-null, then all string comparisons and all regular expression matching are case independent. Thus, regexp matching with ‘~’ and ‘!~’, as well as thegensub(),gsub(),index(),match(),patsplit(),split(), andsub()functions, record termination withRS, and field splitting withFSandFPAT, all ignore case when doing their particular regexp operations. However, the value ofIGNORECASEdoes not affect array subscripting and it does not affect field splitting when using a single-character field separator. See section Case Sensitivity in Matching.If
gawkis in compatibility mode (see section Command-Line Options), thenIGNORECASEhas no special meaning. Thus, string and regexp operations are always case-sensitive.-
LINT # When this variable is true (nonzero or non-null),
gawkbehaves as if the ‘--lint’ command-line option is in effect. (see section Command-Line Options). With a value of"fatal", lint warnings become fatal errors. With a value of"invalid", only warnings about things that are actually invalid are issued. (This is not fully implemented yet.) Any other true value prints nonfatal warnings. Assigning a false value toLINTturns off the lint warnings.This variable is a
gawkextension. It is not special in otherawkimplementations. Unlike the other special variables, changingLINTdoes affect the production of lint warnings, even ifgawkis in compatibility mode. Much as the ‘--lint’ and ‘--traditional’ options independently control different aspects ofgawk’s behavior, the control of lint warnings during program execution is independent of the flavor ofawkbeing executed.-
OFMT This string controls conversion of numbers to strings (see section Conversion of Strings and Numbers) for printing with the
printstatement. It works by being passed as the first argument to thesprintf()function (see section String-Manipulation Functions). Its default value is"%.6g". Earlier versions ofawkalso usedOFMTto specify the format for converting numbers to strings in general expressions; this is now done byCONVFMT.-
OFS This is the output field separator (see section Output Separators). It is output between the fields printed by a
printstatement. Its default value is" ", a string consisting of a single space.-
ORS This is the output record separator. It is output at the end of every
printstatement. Its default value is"\n", the newline character. (See section Output Separators.)-
RS This is
awk’s input record separator. Its default value is a string containing a single newline character, which means that an input record consists of a single line of text. It can also be the null string, in which case records are separated by runs of blank lines. If it is a regexp, records are separated by matches of the regexp in the input text. (See section How Input Is Split into Records.)The ability for
RSto be a regular expression is agawkextension. In most otherawkimplementations, or ifgawkis in compatibility mode (see section Command-Line Options), just the first character ofRS’s value is used.-
SUBSEP This is the subscript separator. It has the default value of
"\034"and is used to separate the parts of the indices of a multidimensional array. Thus, the expressionfoo["A", "B"]really accessesfoo["A\034B"](see section Multidimensional Arrays).-
TEXTDOMAIN # This variable is used for internationalization of programs at the
awklevel. It sets the default text domain for specially marked string constants in the source text, as well as for thedcgettext(),dcngettext()andbindtextdomain()functions (see section Internationalization withgawk). The default value ofTEXTDOMAINis"messages".This variable is a
gawkextension. In otherawkimplementations, or ifgawkis in compatibility mode (see section Command-Line Options), it is not special.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
