gawk: PC Using
1
1 B.3.1.3 Using 'gawk' on PC Operating Systems
1 ............................................
1
1 Information in this section applies to the MinGW and DJGPP ports of
1 'gawk'. ⇒Cygwin for information about the Cygwin port.
1
1 Under MS-Windows, the MinGW environment supports both the '|&'
1 operator and TCP/IP networking (⇒TCP/IP Networking). The DJGPP
1 environment does not support '|&'.
1
1 The MS-Windows version of 'gawk' searches for program files as
1 described in ⇒AWKPATH Variable. However, semicolons (rather than
1 colons) separate elements in the 'AWKPATH' variable. If 'AWKPATH' is
1 not set or is empty, then the default search path is
1 '.;c:/lib/awk;c:/gnu/lib/awk'.
1
1 Under MS-Windows, 'gawk' (and many other text programs) silently
1 translates end-of-line '\r\n' to '\n' on input and '\n' to '\r\n' on
1 output. A special 'BINMODE' variable (c.e.) allows control over these
1 translations and is interpreted as follows:
1
1 * If 'BINMODE' is '"r"' or one, then binary mode is set on read
1 (i.e., no translations on reads).
1
1 * If 'BINMODE' is '"w"' or two, then binary mode is set on write
1 (i.e., no translations on writes).
1
1 * If 'BINMODE' is '"rw"' or '"wr"' or three, binary mode is set for
1 both read and write.
1
1 * 'BINMODE=NON-NULL-STRING' is the same as 'BINMODE=3' (i.e., no
1 translations on reads or writes). However, 'gawk' issues a warning
1 message if the string is not one of '"rw"' or '"wr"'.
1
1 The modes for standard input and standard output are set one time only
1 (after the command line is read, but before processing any of the 'awk'
1 program). Setting 'BINMODE' for standard input or standard output is
1 accomplished by using an appropriate '-v BINMODE=N' option on the
1 command line. 'BINMODE' is set at the time a file or pipe is opened and
1 cannot be changed midstream.
1
11 The name 'BINMODE' was chosen to match 'mawk' (⇒Other
Versions). 'mawk' and 'gawk' handle 'BINMODE' similarly; however,
1 'mawk' adds a '-W BINMODE=N' option and an environment variable that can
1 set 'BINMODE', 'RS', and 'ORS'. The files 'binmode[1-3].awk' (under
1 'gnu/lib/awk' in some of the prepared binary distributions) have been
1 chosen to match 'mawk''s '-W BINMODE=N' option. These can be changed or
1 discarded; in particular, the setting of 'RS' giving the fewest
1 "surprises" is open to debate. 'mawk' uses 'RS = "\r\n"' if binary mode
1 is set on read, which is appropriate for files with the MS-DOS-style
1 end-of-line.
1
1 To illustrate, the following examples set binary mode on writes for
1 standard output and other files, and set 'ORS' as the "usual"
1 MS-DOS-style end-of-line:
1
1 gawk -v BINMODE=2 -v ORS="\r\n" ...
1
1 or:
1
1 gawk -v BINMODE=w -f binmode2.awk ...
1
1 These give the same result as the '-W BINMODE=2' option in 'mawk'. The
1 following changes the record separator to '"\r\n"' and sets binary mode
1 on reads, but does not affect the mode on standard input:
1
1 gawk -v RS="\r\n" -e "BEGIN { BINMODE = 1 }" ...
1
1 or:
1
1 gawk -f binmode1.awk ...
1
1 With proper quoting, in the first example the setting of 'RS' can be
1 moved into the 'BEGIN' rule.
1