21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 6: Patterns, Actions, and Variables 111BINMODE # 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, orall files, respectively, should use binary I/O. A numeric value less than zerois 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" indicatesthat all files should use binary I/O. Any other string value is equivalent to "rw",but gawk generates a warning message. BINMODE is described in more detail inSection B.3.1.4 [Using gawk on PC Operating Systems], page 273.This variable is a gawk extension. In other awk implementations (except mawk,see Section B.6 [Other Freely Available awk Implementations], page 281), orif gawk is in compatibility mode (see Section 11.2 [Command-Line Options],page 177), it is not special.CONVFMTThis string controls conversion of numbers to strings (see Section 5.4 [Conversionof Strings and Numbers], page 79). It works by being passed, in effect,as the first argument to the sprintf function (see Section 8.1.3 [String-Manipulation Functions], page 132). Its default value is "%.6g". CONVFMT wasintroduced by the POSIX standard.FIELDWIDTHS #This is a space-separated list of columns that tells gawk how to split input withfixed columnar boundaries. Assigning a value to FIELDWIDTHS overrides the useof FS for field splitting. See Section 3.6 [Reading Fixed-Width Data], page 48,for more information.If gawk is in compatibility mode (see Section 11.2 [Command-Line Options],page 177), then FIELDWIDTHS has no special meaning, and field-splitting operationsoccur based exclusively on the value of FS.FSThis is the input field separator (see Section 3.5 [Specifying How Fields Are Separated],page 43). The value is a single-character string or a multi-character regularexpression that matches the separations between fields in an input record.If the value is the null string (""), then each character in the record becomes aseparate field. (This behavior is a gawk extension. POSIX awk does not specifythe behavior when FS is the null string.)The default value is " ", a string consisting of a single space. As a specialexception, this value means that any sequence of spaces, TABs, and/or newlinesis a single separator. 2 It also causes spaces, TABs, and newlines at the beginningand end of a record to be ignored.You can set the value of FS on the command line using the ‘-F’ option:awk -F, ’program’ input-filesIf gawk is using FIELDWIDTHS for field splitting, assigning a value to FS causesgawk to return to the normal, FS-based field splitting. An easy way to do thisis to simply say ‘FS = FS’, perhaps with an explanatory comment.2 In POSIX awk, newline does not count as whitespace.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!