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 4: Printing Output 71These special file names may be used on the command line as data files, as well as forI/O redirections within an awk program. They may not be used as source files with the ‘-f’option.NOTE: The special files that provide process-related information are now consideredobsolete and will disappear entirely in the next release of gawk. gawkprints a warning message every time you use one of these files. To obtainprocess-related information, use the PROCINFO array. See Section 6.5.2 [Built-inVariables That Convey Information], page 113.4.7.3 Special Files for Network CommunicationsStarting with version 3.1 of gawk, awk programs can open a two-way TCP/IP connection,acting as either a client or a server. This is done using a special file name of the form:‘/inet/protocol/local-port/remote-host/remote-port’The protocol is one of ‘tcp’, ‘udp’, or ‘raw’, and the other fields represent the otheressential pieces of information for making a networking connection. These file names areused with the ‘|&’ operator for communicating with a coprocess (see Section 10.2 [Two-Way Communications with Another Process], page 170). This is an advanced feature,mentioned here only for completeness. Full discussion is delayed until Section 10.3 [Usinggawk for Network <strong>Programming</strong>], page 172.4.7.4 Special File Name CaveatsHere is a list of things to bear in mind when using the special file names that gawk provides:• Recognition of these special file names is disabled if gawk is in compatibility mode (seeSection 11.2 [Command-Line Options], page 177).• As mentioned earlier, the special files that provide process-related information are nowconsidered obsolete and will disappear entirely in the next release of gawk. gawk printsa warning message every time you use one of these files.• Starting with version 3.1, gawk always interprets these special file names. 1 For example,using ‘/dev/fd/4’ for output actually writes on file descriptor 4, and not on a new filedescriptor that is dup’ed from file descriptor 4. Most of the time this does not matter;however, it is important to not close any of the files related to file descriptors 0, 1, and2. Doing so results in unpredictable behavior.4.8 Closing Input and Output RedirectionsIf the same file name or the same shell command is used with getline more than onceduring the execution of an awk program (see Section 3.8 [Explicit Input with getline],page 52), the file is opened (or the command is executed) the first time only. At that time,the first record of input is read from that file or command. The next time the same file orcommand is used with getline, another record is read from it, and so on.1 Older versions of gawk would interpret these names internally only if the system did not actually have a‘/dev/fd’ directory or any of the other special files listed earlier. Usually this didn’t make a difference,but sometimes it did; thus, it was decided to make gawk’s behavior consistent on all systems and to haveit always interpret the special file names itself.

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

Saved successfully!

Ooh no, something went wrong!