Next: , Previous: , Up: PC Installation   [Contents][Index]


B.3.1.3 Using gawk on PC Operating Systems

Under MS-Windows, the Cygwin and MinGW environments support both the ‘|&’ operator and TCP/IP networking (see TCP/IP Networking).

The MS-Windows version of gawk searches for program files as described in AWKPATH Variable. However, semicolons (rather than colons) separate elements in the AWKPATH variable. If AWKPATH is not set or is empty, then the default search path is ‘.;c:/lib/awk;c:/gnu/lib/awk’.

Under MS-Windows, gawk (and many other text programs) silently translates end-of-line ‘\r\n’ to ‘\n’ on input and ‘\n’ to ‘\r\n’ on output. A special BINMODE variable (c.e.) allows control over these translations and is interpreted as follows:

The modes for standard input and standard output are set one time only (after the command line is read, but before processing any of the awk program). Setting BINMODE for standard input or standard output is accomplished by using an appropriate ‘-v BINMODE=N’ option on the command line. BINMODE is set at the time a file or pipe is opened and cannot be changed midstream.

The name BINMODE was chosen to match mawk (see Other Versions). mawk and gawk handle BINMODE similarly; however, mawk adds a ‘-W BINMODE=N’ option and an environment variable that can set BINMODE, RS, and ORS. The files binmode[1-3].awk (under gnu/lib/awk in some of the prepared binary distributions) have been chosen to match mawk’s ‘-W BINMODE=N’ option. These can be changed or discarded; in particular, the setting of RS giving the fewest “surprises” is open to debate. mawk uses ‘RS = "\r\n"’ if binary mode is set on read, which is appropriate for files with the MS-DOS-style end-of-line.

To illustrate, the following examples set binary mode on writes for standard output and other files, and set ORS as the “usual” MS-DOS-style end-of-line:

gawk -v BINMODE=2 -v ORS="\r\n" …

or:

gawk -v BINMODE=w -f binmode2.awk …

These give the same result as the ‘-W BINMODE=2’ option in mawk. The following changes the record separator to "\r\n" and sets binary mode on reads, but does not affect the mode on standard input:

gawk -v RS="\r\n" -e "BEGIN { BINMODE = 1 }" …

or:

gawk -f binmode1.awk …

With proper quoting, in the first example the setting of RS can be moved into the BEGIN rule.


Next: , Previous: , Up: PC Installation   [Contents][Index]