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 113[Command-Line Options], page 177), just the first character of RS’s value isused.SUBSEP This is the subscript separator. It has the default value of "\034" and isused to separate the parts of the indices of a multidimensional array. Thus,the expression foo["A", "B"] really accesses foo["A\034B"] (see Section 7.9[Multidimensional Arrays], page 125).TEXTDOMAIN #This variable is used for internationalization of programs at the awk level. Itsets the default text domain for specially marked string constants in the sourcetext, as well as for the dcgettext, dcngettext and bindtextdomain functions(see Chapter 9 [Internationalization with gawk], page 160). The default valueof TEXTDOMAIN is "messages".This variable is a gawk extension. In other awk implementations, or if gawk isin compatibility mode (see Section 11.2 [Command-Line Options], page 177),it is not special.6.5.2 Built-in Variables That Convey InformationThe following is an alphabetical list of variables that awk sets automatically on certainoccasions in order to provide information to your program. The variables that are specificto gawk are marked with a pound sign (‘#’).ARGC, ARGVARGIND #The command-line arguments available to awk programs are stored in an arraycalled ARGV. ARGC is the number of command-line arguments present. SeeSection 11.3 [Other Command-Line Arguments], page 182. Unlike most awkarrays, ARGV is indexed from 0 to ARGC − 1. In the following example:$ awk ’BEGIN {> for (i = 0; i < ARGC; i++)> print ARGV[i]> }’ inventory-shipped BBS-list⊣ awk⊣ inventory-shipped⊣ BBS-listARGV[0] contains "awk", ARGV[1] contains "inventory-shipped", andARGV[2] contains "BBS-list". The value of ARGC is three, one more than theindex of the last element in ARGV, because the elements are numbered fromzero.The names ARGC and ARGV, as well as the convention of indexing the arrayfrom 0 to ARGC − 1, are derived from the C language’s method of accessingcommand-line arguments.The value of ARGV[0] can vary from system to system. Also, you should notethat the program text is not included in ARGV, nor are any of awk’s commandlineoptions. See Section 6.5.3 [Using ARGC and ARGV], page 116, for informationabout how awk uses these variables.The index in ARGV of the current file being processed. Every time gawk opensa new data file for processing, it sets ARGIND to the index in ARGV of the file

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

Saved successfully!

Ooh no, something went wrong!