source: trunk/essentials/sys-apps/gawk/doc/awkcard.in

Last change on this file was 3076, checked in by bird, 18 years ago

gawk 3.1.5

File size: 58.2 KB
Line 
1.\" AWK Reference Card --- Arnold Robbins, arnold@skeeve.com
2.\"
3.\" Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002,
4.\" 2003, 2004, 2005 Free Software Foundation, Inc.
5.\"
6.\" Permission is granted to make and distribute verbatim copies of
7.\" this reference card provided the copyright notice and this permission
8.\" notice are preserved on all copies.
9.\"
10.\" Permission is granted to process this file through troff and print the
11.\" results, provided the printed document carries copying permission
12.\" notice identical to this one except for the removal of this paragraph
13.\" (this paragraph not being relevant to the printed reference card).
14.\"
15.\" Permission is granted to copy and distribute modified versions of this
16.\" reference card under the conditions for verbatim copying, provided that
17.\" the entire resulting derived work is distributed under the terms of a
18.\" permission notice identical to this one.
19.\"
20.\" Permission is granted to copy and distribute translations of this
21.\" reference card into another language, under the above conditions for
22.\" modified versions, except that this permission notice may be stated in
23.\" a translation approved by the Foundation.
24.\"
25.\" Strings to save typing
26.ds AK \*(FCawk\*(FR
27.ds GK \*(FCgawk\*(FR
28.ds PK \*(FCpgawk\*(FR
29.ds NK Bell Labs \*(FCawk\*(FR
30.ds MK \*(FCmawk\*(FR
31.\"
32.\"
33.de TD\" tab defaults
34.ta .2i .78i 1i 1.2i 1.4i 1.7i
35..
36.de TE
37.TD
38..
39
40.sp
41.ce
42\*(CD\f(HB\s+8AWK REFERENCE\s0\*(FR
43.sp
44.\" --- Table Of Contents
45.ta 2.4i 2.6iR
46.lc .
47.ES
48.in +.2i
49.nf
50\*(FRAction Statements 7
51Arrays 11
52Awk Program Execution 4
53Bit Manipulation Functions (\*(GK) 16
54Bug Reports 2
55Closing Redirections 12
56Command Line Arguments (standard) 2
57Command Line Arguments (\*(GK) 3
58Command Line Arguments (\*(MK) 4
59Conversions And Comparisons 9
60Copying Permissions 18
61Definitions 2
62Dynamic Extensions (\*(GK) 14
63Environment Variables (\*(GK) 16
64Escape Sequences 8
65Expressions 11
66Fields 6
67FTP/HTTP Information 18
68Historical Features (\*(GK) 10
69Input Control 12
70Internationalization (\*(GK) 18
71Lines And Statements 5
72Localization (\*(GK) 17
73Numeric Functions 14
74Output Control 12
75Pattern Elements 7
76POSIX Character Classes (\*(GK) 6
77Printf Formats 13
78Records 6
79Regular Expressions 5
80Signals (\*(PK) 4
81Special Filenames 14
82String Functions 15
83Time Functions (\*(GK) 16
84User-defined Functions 17
85Variables 8\*(CX
86.in -.2i
87.EB "\s+2\f(HBCONTENTS\*(FR\s0"
88.sp .4
89.TD
90.fi
91\*(CD\*(FRArnold Robbins wrote this reference card.
92We thank
93Brian Kernighan and Michael Brennan who reviewed it.
94.sp .4
95.SL
96.sp .4
97.so SRCDIR/ad.block
98.\" a subtlety here; this line changes color. We rely on it
99.\" also to provide a blank line.
100\*(CD
101.SL
102.nf
103\*(FRCopyright \(co 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
104Free Software Foundation, Inc.
105.nf
106.BT
107
108
109.\"
110.\"
111.\" --- Definitions
112.fi
113.ES
114\*(CDThis card describes POSIX AWK, as well as the three
115freely available \*(AK implementations
116(see \fHFTP/HTTP Information\fP below).
117\*(CLCommon extensions (in two or more versions) are printed in light blue.
118\*(CBFeatures specific to just one version\(emusually GNU AWK (\*(GK)\(emare
119printed in dark blue.
120\*(CRExceptions and deprecated features are printed in red.
121\*(CDFeatures mandated by POSIX are printed in black.
122.sp .5
123Several type faces are used to clarify the meaning:
124.br
125.nr IN \w'\(bu '
126\(bu \*(FC\*(CN\fP is used for computer input.
127.br
128.fi
129.in +\n(INu
130.ti -\n(INu
131\(bu\|\^\*(FI\*(IN\fP is used for emphasis, to indicate user input and for syntactic
132placeholders, such as \*(FIvariable\fP or \*(FIaction\fP.
133.in -\n(INu
134.br
135\(bu \*(RN is used for explanatory text.
136.sp .5
137\*(FInumber\fP \- a floating point number as in ANSI C, such as
138\*(FC3\*(FR,
139\*(FC2.3\*(FR,
140\*(FC.4\*(FR,
141\*(FC1.4e2\*(FR
142or
143\*(FC4.1E5\*(FR.
144\*(CBNumbers may also be given in octal or hexadecimal: e.g.,
145\*(FC011\*(FR or \*(FC0x11\*(FR.\*(CD
146.sp .5
147\*(FIescape sequences\fP \- a special sequence of characters beginning
148with a backslash, used to describe otherwise unprintable characters.
149(See \fHEscape Sequences\fP below.)
150.sp .5
151\*(FIstring\fP \- a group of characters enclosed in double quotes.
152Strings may contain \*(FIescape sequences\*(FR.
153.sp .5
154\*(FIregexp\fP \- a regular expression, either a regexp constant
155enclosed in forward slashes, or a dynamic regexp computed at run-time.
156Regexp constants may contain \*(FIescape sequences\*(FR.
157.sp .5
158\*(FIname\fP \- a variable, array or function name.
159.sp .5
160\*(FIentry\fP(\*(FIN\fP) \- entry \*(FIentry\fP in section \*(FIN\fP of the
161UNIX reference manual.
162.sp .5
163\*(FIpattern\fP \- an expression describing an input record to be matched.
164.sp .5
165\*(FIaction\fP \- statements to execute when an input record is matched.
166.sp .5
167\*(FIrule\fP \- a pattern-action pair, where the pattern or action may
168be missing.\*(CX
169.EB "\s+2\f(HBDEFINITIONS\*(FR\s0"
170
171.\"
172.\"
173.\" --- Command Line Arguments
174.ES
175.fi
176\*(CDCommand line arguments control setting the field separator,
177setting variables before the \*(FCBEGIN\fP rule is run, and
178the location of AWK program source code.
179Implementation-specific command line arguments change
180the behavior of the running interpreter.
181.sp .5
182.TS
183expand;
184l lw(2.2i).
185\*(FC\-F \*(FIfs\*(FR use \*(FIfs\fP for the input field separator.
186\*(FC\-v\*(FI var\*(FC\^=\^\*(FIval\*(FR T{
187assign the value \*(FIval\*(FR to the variable \*(FIvar\*(FR
188before execution of the program begins. Such
189variable values are available to the \*(FCBEGIN\fP rule.
190T}
191\*(FC\-f \*(FIprog-file\*(FR T{
192read the AWK program source from the file
193\*(FIprog-file\*(FR, instead of from the first command
194line argument. Multiple \*(FC\-f\*(FR options may be used.
195T}
196\*(FC\-\^\-\*(FR signal the end of options.
197.TE
198.sp .5
199.fi
200\*(CLThe following options are accepted by both \*(NK and \*(GK
201\*(CR(ignored by \*(GK, not in \*(MK).\*(CL
202.sp .5
203.nf
204.TS
205expand, tab(%);
206l lw(2.2i).
207\*(FC\-mf \*(FIval\*(FR%set the maximum number of fields to \*(FIval\fP
208\*(FC\-mr \*(FIval\*(FR%set the maximum record size to \*(FIval\fP\*(CX
209.TE
210.EB "\s+2\f(HBCOMMAND LINE ARGUMENTS (standard)\*(FR\s0"
211
212.\" --- Bug Reports
213.ES
214.fi
215\*(CDIf you find a bug in this reference card, please report it via electronic
216mail to \*(FCbug-gawk@gnu.org\*(FR.\*(CX
217.EB "\s+2\f(HBBUG REPORTS\*(FR\s0"
218
219.BT
220
221.\"
222.\"
223.\" --- Command Line Arguments (gawk)
224.ES
225.fi
226\*(CDThe following options are specific to \*(GK.
227You may also use ``\*(FC\-W \*(FIoption\*(FR''
228for full POSIX compliance.
229Long options may abbreviated as long as the abbreviation
230remains unique.
231.sp .5
232.ig
233.\" This option is left undocumented, on purpose.
234\*(FC\-\^\-nostalgia\*(FR%T{
235provide a moment of nostalgia for
236long time \*(AK users.
237T}
238..
239.TS
240expand, tab(%);
241l lw(1.3i).
242\*(FC\-\^\-assign \*(FIvar\*(FC\^=\^\*(FIval\*(FR%just like \*(FC\-v\fP.
243\*(FC\-\^\-field-separator \*(FIfs\*(FR%just like \*(FC\-F\fP.
244\*(FC\-\^\-file \*(FIprog-file%\*(FRjust like \*(FC\-f\fP.
245.TE
246.TS
247expand, tab(%);
248ls
249l lw(2.2i).
250\*(FC\-\^\-compat\*(FR, \*(FC\-\^\-traditional\*(FR
251%T{
252disable \*(GK-specific extensions
253(the use of \*(FC\-\^\-traditional\*(FR is preferred).
254T}
255.T&
256ls
257l lw(2.2i).
258\*(FC\-\^\-copyleft\*(FR, \*(FC\-\^\-copyright\*(FR
259%T{
260print the short version of the GNU
261copyright information on \*(FCstdout\*(FR.
262T}
263.T&
264ls
265l lw(2.2i).
266\*(FC\-\^\-dump-variables\*(FR[\*(FC=\*(FIfile\*(FR]
267%T{
268print a sorted list of global variables,
269their types and final values to
270\*(FIfile\*(FR.
271If no \*(FIfile\*(FR
272is provided, \*(FCgawk\*(FR
273uses \*(FCawkvars.out\*(FR.
274T}
275\*(FC\-\^\-exec \*(FIfile\*(FR%T{
276read program text from \*(FIfile\fP. No other
277options are processed. Useful with \*(FC#!\fP.
278Also disables command-line variable assignments.
279T}
280\*(FC\-\^\-gen\-po\*(FR%T{
281process the program and print a GNU \*(FCgettext\*(FR
282format \*(FC\&.po\*(FR format file on standard output,
283containing the text of all strings that were marked
284for localization.
285T}
286.T&
287ls
288l lw(2.2i).
289\*(FC\-\^\-help\*(FR, \*(FC\-\^\-usage\*(FR
290%T{
291print a short summary of the available
292options on \*(FCstdout\*(FR, then exit zero.
293T}
294.T&
295ls
296l lw(2.2i).
297\*(FC\-\^\-lint\*(FR[\*(FC=\*(FIvalue\*(FR]
298%T{
299warn about constructs that are dubious
300or non-portable to other \*(AKs.
301With an optional argument of \*(FCfatal\*(FR,
302lint warnings become fatal errors.
303With an optional argument of
304\*(FCinvalid\*(FR,
305only warnings about things that are
306actually invalid are issued. (This is not fully implemented yet.)
307T}
308.T&
309l lw(2.2i).
310\*(FC\-\^\-lint\-old\*(FR%T{
311warn about constructs that are not
312portable to the original version of
313Unix \*(AK.
314T}
315.T&
316ls
317l lw(2.2i).
318\*(FC\-\^\-non\-decimal\-data\*(FR
319%T{
320recognize octal and hexadecimal values in input data.
321\*(FIUse this option with great caution!\*(FR
322T}
323.T&
324l lw(2.2i).
325\*(FC\-\^\-posix\*(FR%T{
326disable common and GNU extensions.
327Enable \*(FIinterval expressions\*(FR in regular
328expression matching (see \fHRegular
329Expressions\fP below).
330T}
331.T&
332ls
333l lw(2.2i).
334\*(FC\-\^\-profile\*(FR[\*(FC=\*(FIprof_file\*(FR]
335%T{
336send profiling data to \*(FIprof_file\*(FR
337(default: \*(FCawkprof.out\*(FR).
338With \*(GK,
339the profile is just a ``pretty printed'' version of the program.
340With \*(PK,
341the profile contains execution counts in the left margin
342of each statement in the program.
343T}
344.T&
345ls
346l lw(2.2i).
347\*(FC\-\^\-re\-interval\*(FR
348%T{
349enable \*(FIinterval expressions\*(FR in regular
350expression matching (see \fHRegular
351Expressions\fP below). Useful if
352\*(FC\-\^\-posix\*(FR is not specified.
353T}
354.T&
355ls
356l lw(2.2i).
357\*(FC\-\^\-source '\*(FItext\*(FC'\*(FR
358%use \*(FItext\*(FR as AWK program source code.
359\*(FC\-\^\-version\*(FR%T{
360print version information on \*(FCstdout\fP
361and exit zero.
362T}
363.TE
364.sp .5
365.fi
366In compatibility mode,
367any other options are flagged as invalid, but are otherwise ignored.
368In normal operation, as long as program text has been supplied, unknown
369options are passed on to the AWK program in
370\*(FCARGV\*(FR
371for processing. This is most useful for running AWK
372programs via the \*(FC#!\*(FR executable interpreter mechanism.\*(CB
373.EB "\s+2\f(HBCOMMAND LINE ARGUMENTS (\*(GK\f(HB)\*(FR\s0"
374
375.BT
376
377.\"
378.\"
379.\" --- Command Line Arguments (mawk)
380.ES
381.fi
382\*(CDThe following options are specific to \*(MK.
383.sp .5
384.fi
385.TS
386expand;
387l lw(1.8i).
388\*(FC\-W dump\*(FR T{
389print an assembly listing of the program to
390\*(FCstdout\fP and exit zero.
391T}
392\*(FC\-W exec \*(FIfile\*(FR T{
393read program text from \*(FIfile\fP. No other
394options are processed. Useful with \*(FC#!\fP.
395T}
396\*(FC\-W interactive\*(FR T{
397unbuffer \*(FCstdout\fP and line buffer \*(FCstdin\fP.
398Lines are always records, ignoring \*(FCRS\fP.
399T}
400\*(FC\-W posix_space\*(FR T{
401\*(FC\en\*(FR separates fields when \*(FCRS = "\^"\fP.
402T}
403\*(FC\-W sprintf=\*(FInum\*(FR T{
404adjust the size of \*(MK's internal
405\*(FCsprintf\*(FR buffer.
406T}
407\*(FC\-W version\*(FR T{
408print version and copyright on
409\*(FCstdout\fP and limit information on \*(FCstderr\fP
410and exit zero.
411T}
412.TE
413.sp .5
414.fi
415The options may be abbreviated using just the first letter, e.g.,
416\*(FC\-We\*(FR,
417\*(FC\-Wv\*(FR
418and so on.\*(CB
419.EB "\s+2\f(HBCOMMAND LINE ARGUMENTS (\*(MK\f(HB)\*(FR\s0"
420.sp .7
421.\" --- Signals (pgawk)
422.ES
423.fi
424\*(CD\*(PK accepts two signals.
425\*(FCSIGUSR1\fP dumps a profile and function call stack to the
426profile file. It then continues to run.
427\*(FCSIGHUP\fP is similar, but exits.\*(CB
428.EB "\s+2\f(HBSIGNALS (\*(PK\f(HB)\*(FR\s0"
429.sp .7
430.\" --- Awk Program Execution
431.ES
432.fi
433\*(CDAWK programs are a sequence of pattern-action statements
434and optional function definitions.
435.sp .5
436 \*(FIpattern\*(FC { \*(FIaction statements\*(FC }\*(FR
437.br
438 \*(FCfunction \*(FIname\*(FC(\*(FIparameter list\*(FC) { \*(FIstatements\*(FC }\*(FR
439.sp .5
440\*(AK first reads the program source from the
441\*(FIprog-file\*(FR(s), if specified,
442\*(CBfrom arguments to \*(FC\-\^\-source\*(FR,\*(CD
443or from the first non-option argument on the command line.
444The program text is read as if all the \*(FIprog-file\*(FR(s)
445\*(CBand command line
446source texts\*(CD had been concatenated.
447.sp .5
448AWK programs execute in the following order.
449First, all variable assignments specified via the \*(FC\-v\fP
450option are performed.
451Next, \*(AK executes the code in the
452\*(FCBEGIN\fP rules(s), if any, and then proceeds to read
453the files \*(FC1\fP through \*(FCARGC \- 1\fP in the \*(FCARGV\fP array.
454(Adjusting \*(FCARGC\fP and \*(FCARGV\fP thus provides control over
455the input files that will be processed.)
456If there are no files named on the command line,
457\*(AK reads the standard input.
458.sp .5
459If a command line argument has the form
460\*(FIvar\*(FC=\*(FIval\*(FR,
461it is treated as a variable assignment. The variable
462\*(FIvar\fP will be assigned the value \*(FIval\*(FR.
463(This happens after any \*(FCBEGIN\fP rule(s) have been run.)
464... delete this paragraph if no space
465Command line variable assignment
466is most useful for dynamically assigning values to the variables
467\*(AK uses to control how input is broken into fields and records. It
468is also useful for controlling state if multiple passes are needed over
469a single data file.
470.sp .5
471If the value of a particular element of \*(FCARGV\fP is empty
472(\*(FC"\^"\*(FR), \*(AK skips over it.
473.sp .5
474For each record in the input, \*(AK tests to see if it matches any
475\*(FIpattern\fP in the AWK program.
476For each pattern that the record matches, the associated
477\*(FIaction\fP is executed.
478The patterns are tested in the order they occur in the program.
479.sp .5
480Finally, after all the input is exhausted,
481\*(AK executes the code in the \*(FCEND\fP rule(s), if any.
482.sp .5
483If a program only has a \*(FCBEGIN\fP rule, no input files are processed.
484If a program only has an \*(FCEND\fP rule, the input will be read.
485\*(CX
486.EB "\s+2\f(HBAWK PROGRAM EXECUTION\*(FR\s0"
487
488
489.BT
490
491.\" --- Lines And Statements
492.ES
493.fi
494\*(CDAWK is a line-oriented language. The pattern comes first, and then the
495action. Action statements are enclosed in \*(FC{\fP and \*(FC}\*(FR.
496Either the pattern or the action may be missing, but
497not both. If the pattern is missing, the action is
498executed for every input record.
499A missing action is equivalent to
500.sp .5
501 \*(FC{ print }\fP
502.sp .5
503which prints the entire record.
504.sp .5
505Comments begin with the \*(FC#\*(FR character, and continue until the
506end of the line.
507Normally, a statement ends with a newline, but lines ending in
508a ``,'',
509\*(FC{\*(FR,
510\*(CB\*(FC?\*(FR,
511\*(FC:\*(FR,\*(CD
512\*(FC&&\*(FR
513or
514\*(FC||\*(FR
515are automatically continued.
516Lines ending in \*(FCdo\fP or \*(FCelse\fP
517also have their statements automatically continued on the following line.
518In other cases, a line can be continued by ending it with a ``\e'',
519in which case the newline is ignored. However, a ``\e'' after a
520\*(FC#\*(FR is not special.
521.sp .5
522Multiple statements may be put on one line by separating them with a ``;''.
523This applies to both the statements within the action part of a
524pattern-action pair (the usual case)
525and to the pattern-action statements themselves.\*(CX
526.EB "\s+2\f(HBLINES AND STATEMENTS\*(FR\s0"
527
528
529
530.\" --- Regular Expressions
531.ES
532.fi
533\*(CDRegular expressions are the extended kind originally defined by
534\*(FCegrep\fP.
535\*(CBAdditional GNU regexp operators are supported by \*(GK.
536A \*(FIword-constituent\fP character is a letter, digit, or
537underscore (\*(FC_\fP).\*(CD
538.sp .5
539.TS
540center, tab(~);
541cp8 sp8
542cp8 sp8
543lp8|lp8.
544.\" .vs 10
545_
546Summary of Regular Expressions
547In Decreasing Precedence
548_
549\*(FC(\^\*(FIr\*(FC)\*(FR~regular expression (for grouping)
550\*(FIc\*(FR~if non-special char, matches itself
551\*(FC\e\*(FI\^c\*(FR~turn off special meaning of \*(FIc\fP
552\*(FC^\*(FR~beginning of string (note: \*(FInot\fP line)
553\*(FC$\*(FR~end of string (note: \*(FInot\fP line)
554\*(FC.\*(FR~any single character, including newline
555\*(FC[\*(FR...\*(FC]\*(FR~any one character in ... or range
556\*(FC[^\*(FR...\*(FC]\*(FR~any one character not in ... or range
557\*(CB\*(FC\ey\*(FR~word boundary
558\*(FC\eB\*(FR~middle of a word
559\*(FC\e<\*(FR~beginning of a word
560\*(FC\e>\*(FR~end of a word
561\*(FC\ew\*(FR~any word-constituent character
562\*(FC\eW\*(FR~any non-word-constituent character
563\*(FC\e`\*(FR~beginning of a string
564\*(FC\e'\*(FR~end of a string\*(CD
565\*(FIr\*(FC*\*(FR~zero or more occurrences of \*(FIr\*(FR
566\*(FIr\*(FC+\*(FR~one or more occurrences of \*(FIr\*(FR
567\*(FIr\*(FC?\*(FR~zero or one occurrences of \*(FIr\*(FR
568\*(FIr\*(FC{\*(FIn\*(FC,\*(FIm\*(FC}\*(FR~\*(FIn\fP to \*(FIm\fP occurrences of \*(FIr\*(FR \*(CR(POSIX: see note below)\*(CD
569\*(FIr1\*(FC|\|\*(FIr2\*(FR~\*(FIr1\*(FR or \*(FIr2\*(FR
570.TE
571.sp .5
572.fi
573\*(CRThe \*(FIr\*(FC{\*(FIn\*(FC,\*(FIm\*(FC}\*(FR notation is called an
574\*(FIinterval expression\fP. POSIX mandates it for AWK regexps, but
575most \*(AKs don't implement it. \*(CBUse \*(FC\-\^\-re\-interval\*(FR
576or \*(FC\-\^\-posix\*(FR to enable
577this feature in \*(GK.\*(CX
578.EB "\s+2\f(HBREGULAR EXPRESSIONS\*(FR\s0"
579
580
581.BT
582
583.\" --- POSIX Character Classes (gawk)
584.ES
585.fi
586\*(CDIn regular expressions, within character ranges
587(\*(FC[\*(FR...\*(FC]\*(FR),
588the notation \*(FC[[:\*(FIclass\*(FC:]]\*(FR defines character classes:
589.sp .5
590.TS
591center, tab(~);
592lp8 lp8 lp8 lp8.
593\*(FCalnum\*(FR~alphanumeric~\*(FClower\*(FR~lower-case
594\*(FCalpha\*(FR~alphabetic~\*(FCprint\*(FR~printable
595\*(FCblank\*(FR~space or tab~\*(FCpunct\*(FR~punctuation
596\*(FCcntrl\*(FR~control~\*(FCspace\*(FR~whitespace
597\*(FCdigit\*(FR~decimal~\*(FCupper\*(FR~upper-case
598\*(FCgraph\*(FR~non-spaces~\*(FCxdigit\*(FR~hexadecimal
599.TE
600.fi
601.sp .5
602Recognition of these character classes is disabled
603when \*(FC\-\-traditional\*(FR is supplied.\*(CB
604.EB "\s+2\f(HBPOSIX CHARACTER CLASSES (\*(GK\f(HB)\*(FR\s0"
605
606.\" --- Records
607.ES
608.fi
609\*(CDNormally, records are separated by newline characters.
610Assigning values to the built-in variable \*(FCRS\*(FR
611controls how records are separated.
612If \*(FCRS\fP is any single character, that character separates records.
613\*(CLOtherwise, \*(FCRS\fP is a regular expression.
614\*(CR(Not \*(NK.)\*(CL
615Text in the input that matches this
616regular expression separates the record.
617\*(CB\*(GK sets \*(FCRT\*(FR to the value of the
618input text that matched the regular expression.
619The value of \*(FCIGNORECASE\fP
620also affects how records are separated when
621\*(FCRS\fP is a regular expression.\*(CD
622If \*(FCRS\fP is set to the null string,
623then records are separated by one or more blank lines.
624When \*(FCRS\fP is set to the null string,
625the newline character always acts as
626a field separator, in addition to whatever value
627\*(FCFS\fP may have.
628\*(CB\*(MK does not apply exceptional rules to \*(FCFS\fP
629when \*(FCRS = "\^"\fP.\*(CX
630.EB "\s+2\f(HBRECORDS\*(FR\s0"
631
632.\" --- Fields
633.ES
634.fi
635\*(CDAs each input record is read, \*(AK splits the record into
636\*(FIfields\*(FR, using the value of the \*(FCFS\fP
637variable as the field separator.
638If \*(FCFS\fP is a single character,
639fields are separated by that character.
640\*(CLIf \*(FCFS\fP is the null string,
641then each individual character becomes a separate field.\*(CD
642Otherwise, \*(FCFS\fP is expected to be a full regular expression.
643In the special case that \*(FCFS\fP
644is a single space, fields are separated
645by runs of spaces and/or tabs
646\*(CLand/or newlines\*(CD.
647Leading and trailing whitespace are ignored.
648\*(CBThe value of \*(FCIGNORECASE\fP
649also affects how fields are split when
650\*(FCFS\fP is a regular expression.\*(CD
651.sp .5
652\*(CBIf the \*(FCFIELDWIDTHS\fP
653variable is set to a space-separated list of numbers, each field is
654expected to have a fixed width, and \*(GK
655splits up the record using the specified widths.
656The value of \*(FCFS\fP is ignored.
657Assigning a new value to \*(FCFS\fP
658overrides the use of \*(FCFIELDWIDTHS\*(FR,
659and restores the default behavior.\*(CD
660.sp .5
661Each field in the input record may be referenced by its position,
662\*(FC$1\*(FR, \*(FC$2\*(FR and so on.
663\*(FC$0\fP is the whole record.
664Fields may also be assigned new values.
665.sp .5
666The variable \*(FCNF\fP
667is set to the total number of fields in the input record.
668.sp .5
669References to non-existent fields (i.e., fields after \*(FC$NF\*(FR)
670produce the null-string. However, assigning to a non-existent field
671(e.g., \*(FC$(NF+2) = 5\*(FR) increases the value of
672\*(FCNF\*(FR, creates any intervening fields with the null string as their value,
673and causes the value of \*(FC$0\fP
674to be recomputed with the fields being separated by the
675value of \*(FCOFS\*(FR.
676References to negative numbered fields cause a fatal error.
677Decreasing the value of \*(FCNF\fP causes the trailing fields to be lost
678\*(CR(not \*(NK).\*(CX
679.EB "\s+2\f(HBFIELDS\*(FR\s0"
680
681.BT
682
683.\" --- Pattern Elements
684.ES
685.fi
686\*(CDAWK patterns may be one of the following.
687.sp .5
688.nf
689 \*(FCBEGIN
690 END
691 \*(FIexpression
692 pat1\*(FC,\*(FIpat2\*(FR
693.sp .5
694.fi
695\*(FCBEGIN\fP and \*(FCEND\fP are special patterns that provide start-up
696and clean-up actions respectively. They must have actions. There can
697be multiple \*(FCBEGIN\fP and \*(FCEND\fP rules; they are merged and
698executed as if there had just been one large rule. They may occur anywhere
699in a program, including different source files.
700.sp .5
701Expression patterns can be any expression, as described
702under \fHExpressions\fP.
703.sp .5
704The \*(FIpat1\*(FC,\*(FIpat2\*(FR pattern
705is called a \*(FIrange pattern\*(FR.
706It matches all input records starting with a record that matches
707\*(FIpat1\*(FR, and continuing until a record that matches
708\*(FIpat2\*(FR, inclusive.
709It does not combine with any other pattern expression.\*(CX
710.EB "\s+2\f(HBPATTERN ELEMENTS\*(FR\s0"
711
712
713.\" --- Action Statements
714.ES
715.fi
716.in +.2i
717.ti -.2i
718\*(CD\*(FCbreak\*(FR
719.br
720break out of the nearest enclosing \*(FCdo\*(FR, \*(FCfor\*(FR,
721or \*(FCwhile\*(FR loop.
722.ti -.2i
723\*(FCcontinue\*(FR
724.br
725skip the rest of the loop body.
726Evaluate the \*(FIcondition\*(FR
727part of the nearest enclosing \*(FCdo\*(FR or \*(FCwhile\*(FR loop,
728or go to the \*(FIincr\*(FR part of a \*(FCfor\*(FR loop.
729.ti -.2i
730\*(FCdelete \*(FIarray\^\*(FC[\^\*(FIindex\^\*(FC]\*(FR
731.br
732delete element \*(FIindex\*(FR from array \*(FIarray\*(FR.
733.ti -.2i
734\*(CL\*(FCdelete \*(FIarray\^\*(FR
735.br
736delete all elements from array \*(FIarray\*(FR.\*(CD
737.ti -.2i
738\*(FCdo \*(FIstatement \*(FCwhile (\*(FIcondition\*(FC)\*(FR
739.br
740execute \*(FIstatement\*(FR while \*(FIcondition\*(FR is true.
741The \*(FIstatement\*(FR is always executed at least once.
742.ti -.2i
743\*(FCexit\*(FR [ \*(FIexpression\*(FR ]
744.br
745terminate input record processing.
746Execute the \*(FCEND\*(FR rule(s) if present.
747If present, \*(FIexpression\*(FR becomes \*(AK's return value.
748.ti -.2i
749\*(FCfor (\*(FIinit\*(FC; \*(FIcond\*(FC; \*(FIincr\*(FC) \*(FIstatement\*(FR
750.br
751execute \*(FIinit\*(FR.
752Evaluate \*(FIcond\*(FR.
753If it is true, execute \*(FIstatement\*(FR.
754Execute \*(FIincr\*(FR before going back to the top to
755re-evaluate \*(FIcond\*(FR.
756Any of the three may be omitted.
757A missing \*(FIcond\*(FR is considered to be true.
758.ti -.2i
759\*(FCfor (\*(FIvar \*(FCin\*(FI array\*(FC) \*(FIstatement\*(FR
760.br
761execute \*(FIstatement\*(FR once for each subscript in \*(FIarray\*(FR,
762with \*(FIvar\*(FR set to a different subscript each time through
763the loop.
764.ti -.2i
765\*(CD\*(FCif (\*(FIcondition\*(FC) \*(FIstatement1\*(FR [ \*(FCelse\*(FI statement2\*(FR ]
766.br
767if \*(FIcondition\*(FR is true, execute \*(FIstatement1\*(FR,
768otherwise execute \*(FIstatement2\*(FR. Each \*(FCelse\*(FR
769matches the closest \*(FCif\*(FR.
770.ti -.2i
771\*(FCnext\*(FR see \fHInput Control.\fP
772.ti -.2i
773\*(CL\*(FCnextfile\*(FR \*(CR(not \*(MK) \*(CLsee \fHInput Control.\fP\*(CD
774.ti -.2i
775.\" --- Start switch statement
776\*(CB\*(FCswitch (\*(FIexpression\*(FC) {
777.br
778 case [\*(FIvalue\*(FC|\*(FIregular expression\*(FC] : \*(FIstatement(s)\*(FC
779.br
780 default: \*(FIstatement(s)\*(FC
781.br
782}\*(FR
783.br
784switch on \*(FIexpression\*(FR, execute \*(FIcase\*(FR if matched, default if not.
785For 3.1.x, requires \*(FC\-\^\-enable\-switch\*(FR option to \*(FCconfigure\*(FR.\*(CD
786.ti -.2i
787.\" --- End switch statement
788\*(FCwhile (\*(FIcondition\*(FC) \*(FIstatement \*(FR
789.br
790while \*(FIcondition\*(FR is true, execute \*(FIstatement\*(FR.
791.ti -.2i
792\*(FC{ \*(FIstatements \*(FC}\*(FR
793.br
794a list of statements enclosed in braces can be used anywhere
795that a single statement would otherwise be used.\*(CX
796.in -.2i
797.EB "\s+2\f(HBACTION STATEMENTS\*(FR\s0"
798
799
800.BT
801
802.\" --- Escape Sequences
803.ES
804.fi
805\*(CDWithin strings constants (\*(FC"..."\fP) and regexp
806constants (\*(FC/.../\fP), escape sequences may be used to
807generate otherwise unprintable characters. This table lists
808the available escape sequences.
809.sp .5
810.TS
811center, tab(~);
812lp8 lp8 lp8 lp8.
813\*(FC\ea\fP~alert (bell)~\*(FC\er\fP~carriage return
814\*(FC\eb\fP~backspace~\*(FC\et\fP~horizontal tab
815\*(FC\ef\fP~form feed~\*(FC\ev\fP~vertical tab
816\*(FC\en\fP~newline~\*(FC\e\e\fP~backslash
817\*(FC\e\*(FIddd\*(FR~octal value \*(FIddd\fP~\*(CL\*(FC\ex\*(FIhh\*(FR~hex value \*(FIhh\fP\*(CD
818\*(FC\e"\fP~double quote~\*(FC\e/\fP~forward slash\*(CX
819.TE
820.EB "\s+2\f(HBESCAPE SEQUENCES\*(FR\s0"
821.sp .7
822.\" --- Variables
823.ES
824.fi
825.TS
826expand;
827l lw(2i).
828\*(CD\*(FCARGC\fP T{
829number of command line arguments.
830T}
831\*(CB\*(FCARGIND\fP T{
832index in \*(FCARGV\fP of current data file.\*(CD
833T}
834\*(FCARGV\fP T{
835array of command line arguments. Indexed from
8360 to \*(FCARGC\fP \- 1. Dynamically changing the
837contents of \*(FCARGV\fP can control the files used
838for data.
839T}
840\*(CL\*(FCBINMODE\fP T{
841controls ``binary'' mode for all file I/O. Values of 1, 2, or 3,
842indicate input, output, or all files, respectively, should use binary
843I/O. \*(CR(Not \*(NK.) \*(CLApplies only to non-POSIX systems.
844\*(CBFor \*(GK, string values of \*(FC"r"\fP, or \*(FC"w"\fP specify
845that input files, or output files, respectively, should use binary I/O.
846String values of \*(FC"rw"\fP or \*(FC"wr"\fP specify that all files
847should use binary I/O. Any other string value is treated as \*(FC"rw"\fP,
848but generates a warning message.\*(CD
849T}
850\*(FCCONVFMT\fP T{
851conversion format for numbers, default value
852is \*(FC"%.6g"\*(FR.
853T}
854\*(FCENVIRON\fP T{
855array containing the current environment.
856The array is indexed by the environment
857variables, each element being the value of
858that variable.
859T}
860\*(CB\*(FCERRNO\fP T{
861string describing the error if a
862\*(FCgetline\*(FR
863redirection or read
864fails, or if
865\*(FCclose()\*(FR fails.
866T}
867\*(FCFIELDWIDTHS\fP T{
868white-space separated list of fieldwidths. Used
869to parse the input into fields of fixed width,
870instead of the value of \*(FCFS\fP.\*(CD
871T}
872\*(FCFILENAME\fP T{
873name of the current input file. If no files given
874on the command line, \*(FCFILENAME\fP is ``\-''.
875\*(FCFILENAME\fP is undefined inside the \*(FCBEGIN\fP rule
876(unless set by \*(FCgetline\fP).
877T}
878\*(FCFNR\fP T{
879record number in current input file.
880T}
881\*(FCFS\fP T{
882input field separator, a space by default
883(see \fHFields\fP above).
884T}
885\*(CB\*(FCIGNORECASE\fP T{
886if non-zero, all regular expression and string
887operations ignore case.
888Array subscripting
889is \*(FInot\*(FR affected.
890However, the
891\*(FCasort()\*(FR
892and
893\*(FCasorti()\*(FR
894function are affected.
895T}
896\*(CB\*(FCLINT\fP T{
897provides dynamic control of the \*(FC\-\^\-lint\fP
898option from within an AWK program.
899When true, \*(GK
900prints lint warnings.
901When assigned the string value \*(FC"fatal"\*(FR,
902lint warnings become fatal errors, exactly like
903\*(FC\-\-lint=fatal\*(FR.
904Any other true value just prints warnings.\*(CD
905T}
906\*(FCNF\fP T{
907number of fields in the current input record.
908T}
909\*(FCNR\fP T{
910total number of input records seen so far.\*(CX
911T}
912.TE
913.EB "\s+2\f(HBVARIABLES\*(FR\s0"
914.BT
915
916.\" --- Variables (continued)
917.ES
918.fi
919.TS
920expand;
921l lw(2i).
922\*(CD\*(FCOFMT\fP T{
923output format for numbers, \*(FC"%.6g"\*(FR, by default.
924\*(CROld versions of \*(AK used this for number
925to string conversion.\*(CD
926T}
927\*(FCOFS\fP T{
928output field separator, a space by default.
929T}
930\*(FCORS\fP T{
931output record separator, a newline by default.
932T}
933\*(CB\*(FCPROCINFO\fP T{
934elements of this array provide access to info
935about the running AWK program. See
936\*(AM for details.\*(CD
937T}
938\*(FCRLENGTH\fP T{
939length of the string matched by \*(FCmatch()\*(FR;
940\-1 if no match.
941T}
942\*(FCRS\fP T{
943input record separator, a newline by default
944(see \fHRecords\fP above).
945T}
946\*(FCRSTART\fP T{
947index of the first character matched by
948\*(FCmatch()\*(FR; 0 if no match.
949T}
950\*(CB\*(FCRT\fP T{
951record terminator. \*(GK sets \*(FCRT\fP to the input
952text that matched the character or regular
953expression specified by \*(FCRS\*(FR.\*(CD
954T}
955\*(FCSUBSEP\fP T{
956character(s) used to separate multiple subscripts
957in array elements, by default \*(FC"\e034"\*(FR. (See
958\fHArrays\fP below).
959T}
960\*(CB\*(FCTEXTDOMAIN\fP T{
961the application's text domain for internationalization;
962used to find the localized
963translations for the program's strings.\*(CX
964T}
965.TE
966.EB "\s+2\f(HBVARIABLES (continued)\*(FR\s0"
967
968.\" --- Conversions and Comparisons
969.ES
970.fi
971\*(CDVariables and fields may be (floating point) numbers, strings or both.
972Context determines how the value of a variable is interpreted. If used in
973a numeric expression, it will be treated as a number, if used as a string
974it will be treated as a string.
975.sp .5
976To force a variable to be treated as a number, add 0 to it; to force it
977to be treated as a string, concatenate it with the null string.
978.sp .5
979When a string must be converted to a number, the conversion is accomplished
980using \*(FIstrtod\*(FR(3).
981A number is converted to a string by using the value of \*(FCCONVFMT\fP
982as a format string for \*(FIsprintf\*(FR(3),
983with the numeric value of the variable as the argument.
984However, even though all numbers in AWK are floating-point,
985integral values are \*(FIalways\fP converted as integers.
986.sp .5
987Comparisons are performed as follows:
988If two variables are numeric, they are compared numerically.
989If one value is numeric and the other has a string value that is a
990``numeric string,'' then comparisons are also done numerically.
991Otherwise, the numeric value is converted to a string, and a string
992comparison is performed.
993Two strings are compared, of course, as strings.
994.sp .5
995Note that string constants, such as \*(FC"57"\fP, are \*(FInot\fP
996numeric strings, they are string constants. The idea of ``numeric string''
997only applies to fields, \*(FCgetline\fP input,
998\*(FCFILENAME\*(FR, \*(FCARGV\fP elements, \*(FCENVIRON\fP
999elements and the elements of an array created by
1000\*(FCsplit()\fP that are numeric strings.
1001The basic idea is that \*(FIuser input\*(FR,
1002and only user input, that looks numeric,
1003should be treated that way.
1004\*(CRNote that the POSIX standard applies the concept of
1005``numeric string'' everywhere, even to string constants.
1006However, this is
1007clearly incorrect, and none of the three free \*(AK\*(FRs do this.\*(CD
1008(Fortunately, this is fixed in the next version of the standard.)
1009.sp .5
1010Uninitialized variables have the numeric value 0 and the string value
1011\*(FC"\^"\fP
1012(the null, or empty, string).\*(CX
1013.EB "\s+2\f(HBCONVERSIONS AND COMPARISONS\*(FR\s0"
1014
1015.BT
1016
1017.\" --- Historical Features
1018.ES
1019.fi
1020\*(CD1. It is possible to call the \*(FClength()\fP
1021built-in function not only with no argument, but even without parentheses.
1022This feature is marked as ``deprecated'' in the POSIX standard, and \*(GK
1023issues a warning about its use if \*(FC\-\^\-lint\fP
1024is specified on the command line.
1025.sp .5
10262. The \*(FCcontinue\fP
1027and \*(FCbreak\fP statements may be used outside the body of a
1028\*(FCwhile\*(FR, \*(FCfor\*(FR, or \*(FCdo\fP loop.
1029Historical AWK implementations have treated such usage as
1030equivalent to the \*(FCnext\fP statement.
1031\*(GK supports this usage if \*(FC\-\^\-traditional\fP
1032is specified.\*(CB
1033.EB "\s+2\f(HBHISTORICAL FEATURES (\*(GK\f(HB)\*(FR\s0"
1034
1035.ES
1036\*(CX
1037.sp 47
1038.EB "\s+2\f(HBNOTES\*(FR\s0"
1039
1040.BT
1041
1042.\" --- Arrays
1043.ES
1044.fi
1045\*(CDAn array subscript is an expression between square brackets
1046(\*(FC[ \*(FRand \*(FC]\*(FR).
1047If the expression is a list
1048(\*(FIexpr\*(FC, \*(FIexpr \*(FR...),
1049then the subscript is a string consisting of the
1050concatenation of the (string) value of each expression,
1051separated by the value of the \*(FCSUBSEP\fP variable.
1052This simulates multi-dimensional
1053arrays. For example:
1054.nf
1055.sp .5
1056 \*(FCi = "A";\^ j = "B";\^ k = "C"
1057 x[i, j, k] = "hello, world\en"\*(FR
1058.sp .5
1059.fi
1060assigns \*(FC"hello, world\en"\*(FR to the element of the array
1061\*(FCx\fP
1062indexed by the string \*(FC"A\e034B\e034C"\*(FR. All arrays in AWK
1063are associative, i.e., indexed by string values.
1064.sp .5
1065Use the special operator \*(FCin\fP in an \*(FCif\fP
1066or \*(FCwhile\fP statement to see if a particular value is
1067an array index.
1068.sp .5
1069.nf
1070 \*(FCif (val in array)
1071 print array[val]\*(FR
1072.sp .5
1073.fi
1074If the array has multiple subscripts, use
1075\*(FC(i, j) in array\*(FR.
1076.sp .5
1077Use the \*(FCin\fP construct in a \*(FCfor\fP
1078loop to iterate over all the elements of an array.
1079.sp .5
1080Use the \*(FCdelete\fP statement to delete an
1081element from an array.
1082\*(CLSpecifying just the array name without a subscript in
1083the \*(FCdelete\fP
1084statement deletes the entire contents of an array.\*(CX
1085.EB "\s+2\f(HBARRAYS\*(FR\s0"
1086
1087.\" --- Expressions
1088.ES
1089.fi
1090\*(CDExpressions are used as patterns, for controlling conditional action
1091statements, and to produce parameter values when calling functions.
1092Expressions may also be used as simple statements,
1093particularly if they have side-effects such as assignment.
1094Expressions mix \*(FIoperands\fP and \*(FIoperators\fP. Operands are
1095constants, fields, variables, array elements, and the return
1096values from function calls (both built-in and user-defined).
1097.sp .5
1098Regexp constants (\*(FC/\*(FIpat\*(FC/\*(FR), when used as simple expressions,
1099i.e., not used on the right-hand side of
1100\*(FC~\fP and \*(FC!~\fP, or as arguments to the
1101\*(CB\*(FCgensub()\fP,\*(CD
1102\*(FCgsub()\fP,
1103\*(FCmatch()\fP,
1104\*(FCsplit()\fP,
1105and
1106\*(FCsub()\fP,
1107functions, mean \*(FC$0 ~ /\*(FIpat\*(FC/\*(FR.
1108.sp .5
1109The AWK operators, in order of decreasing precedence, are:
1110.sp .5
1111.fi
1112.TS
1113expand;
1114l lw(1.8i).
1115\*(FC(\&...)\*(FR grouping
1116\*(FC$\fP field reference
1117\*(FC++ \-\^\-\fP T{
1118increment and decrement,
1119prefix and postfix
1120T}
1121\*(FC^\fP \*(CL\*(FC**\*(FR\*(CD exponentiation
1122\*(FC+ \- !\fP unary plus, unary minus, and logical negation
1123\*(FC* / %\fP multiplication, division, and modulus
1124\*(FC+ \-\fP addition and subtraction
1125\*(FIspace\fP string concatenation
1126\*(FC< >\fP less than, greater than
1127\*(FC<= >=\fP less than or equal, greater than or equal
1128\*(FC!= ==\fP not equal, equal
1129\*(FC~ !~\fP regular expression match, negated match
1130\*(FCin\fP array membership
1131\*(FC&&\fP logical AND, short circuit
1132\*(FC||\fP logical OR, short circuit
1133\*(FC?\^:\fP in-line conditional expression
1134.T&
1135l s
1136l lw(1.8i).
1137\*(FC=\0+=\0\-=\0*=\0/=\0%=\0^=\0\*(CL**=\*(CD\fP
1138 assignment operators\*(CX
1139.TE
1140.EB "\s+2\f(HBEXPRESSIONS\*(FR\s0"
1141
1142.BT
1143
1144.\" --- Input Control
1145.ES
1146.fi
1147.TS
1148expand;
1149l lw(1.8i).
1150\*(FCgetline\fP T{
1151set \*(FC$0\fP from next record;
1152set \*(FCNF\*(FR, \*(FCNR\*(FR, \*(FCFNR\*(FR.
1153T}
1154\*(FCgetline < \*(FIfile\*(FR set \*(FC$0\fP from next record of \*(FIfile\*(FR; set \*(FCNF\*(FR.
1155\*(FCgetline \*(FIv\*(FR T{
1156set \*(FIv\fP from next input record;
1157set \*(FCNR\*(FR, \*(FCFNR\*(FR.
1158T}
1159\*(FCgetline \*(FIv \*(FC< \*(FIfile\*(FR set \*(FIv\fP from next record of \*(FIfile\*(FR.
1160\*(FIcmd \*(FC| getline\*(FR pipe into \*(FCgetline\*(FR; set \*(FC$0\*(FR, \*(FCNF\*(FR.
1161\*(FIcmd \*(FC| getline \*(FIv\*(FR pipe into \*(FCgetline\*(FR; set \*(FIv\*(FR.
1162\*(CB\*(FIcmd \*(FC|& getline\*(FR co-process pipe into \*(FCgetline\*(FR; set \*(FC$0\*(FR, \*(FCNF\*(FR.
1163.TE
1164.fi
1165.in +.2i
1166.ti -.2i
1167\*(FIcmd \*(FC|& getline \*(FIv\*(FR
1168.br
1169co-process pipe into \*(FCgetline\*(FR; set \*(FIv\*(FR.
1170.ti -.2i
1171\*(FCnext\fP
1172.br
1173stop processing the current input
1174record. Read next input record and
1175start over with the first pattern in the
1176program. Upon end of the input data,
1177execute any \*(FCEND\fP rule(s).
1178.br
1179.ti -.2i
1180\*(CL\*(FCnextfile\fP
1181.br
1182stop processing the current input file.
1183The next input record comes from the
1184next input file. \*(FCFILENAME\fP \*(CBand
1185\*(FCARGIND\fP\*(CL are updated, \*(FCFNR\fP is reset to 1,
1186and processing starts over with the first
1187pattern in the AWK program. Upon end
1188of input data, execute any \*(FCEND\fP rule(s).
1189\*(CREarlier versions of \*(GK used
1190\*(FCnext file\*(FR, as two words.
1191This usage is no longer supported.
1192\*(CR\*(MK does not currently support \*(FCnextfile\*(FR.\*(CD
1193.in -.2i
1194.sp .5
1195.fi
1196\*(FCgetline\*(FR returns 0 on end of file and \-1 on an error.
1197\*(CBUpon an error, \*(FCERRNO\*(FR contains a string describing
1198the problem.\*(CX
1199.EB "\s+2\f(HBINPUT CONTROL\*(FR\s0"
1200
1201.\" --- Output Control
1202.ES
1203.fi
1204.in +.2i
1205.ti -.2i
1206\*(CL\*(FCfflush(\*(FR[\*(FIfile\^\*(FR]\*(FC)\*(FR
1207.br
1208flush any buffers associated
1209with the open output file or pipe \*(FIfile\*(FR.\*(CD
1210\*(CBIf no \*(FIfile\fP, then flush standard output.
1211If \*(FIfile\fP is null, then flush all open output files and pipes
1212\*(CR(not \*(NK)\*(CD.
1213.ti -.2i
1214\*(FCprint\fP
1215.br
1216print the current record. Terminate output record
1217with \*(FCORS\fP.
1218.ti -.2i
1219\*(FCprint \*(FIexpr-list\*(FR
1220.br
1221print expressions. Each expression is separated
1222by the value of \*(FCOFS\fP. Terminate the output record
1223with \*(FCORS\fP.
1224.ti -.2i
1225\*(FCprintf \*(FIfmt\*(FC, \*(FIexpr-list\*(FR
1226.br
1227format and print (see \fHPrintf Formats\fP below).
1228.ti -.2i
1229\*(FCsystem(\*(FIcmd\*(FC)\*(FR
1230.br
1231execute the command \*(FIcmd\*(FR,
1232and return the exit status
1233\*(CR(may not be available on non-POSIX systems)\*(CD.
1234.sp .5
1235.in -.2i
1236I/O redirections may be used with both \*(FCprint\fP and \*(FCprintf\fP.
1237.sp .5
1238.in +.2i
1239.ti -.2i
1240\*(CD\*(FCprint "hello" > \*(FIfile\*(FR
1241.br
1242print data to \*(FIfile\fP. The first time the file is written to, it
1243is truncated. Subsequent commands append data.
1244.ti -.2i
1245\*(FCprint "hello" >> \*(FIfile\*(FR
1246.br
1247append data to \*(FIfile\fP. The previous contents of \*(FIfile\*(FR are not lost.
1248.ti -.2i
1249\*(FCprint "hello" | \*(FIcmd\*(FR
1250.br
1251print data down a pipeline to \*(FIcmd\*(FR.
1252.ti -.2i
1253\*(CB\*(FCprint "hello" |& \*(FIcmd\*(FR
1254.br
1255print data down a pipeline to co-process \*(FIcmd\*(FR.\*(CX
1256.in -.2i
1257.EB "\s+2\f(HBOUTPUT CONTROL\*(FR\s0"
1258
1259.ES
1260.fi
1261.in +.2i
1262.ti -.2i
1263\*(CD\*(FCclose(\*(FIfile\*(FC)\*(FR
1264.br
1265close input or output file, pipe \*(CBor co-process.\*(CD
1266.ti -.2i
1267\*(CB\*(FCclose(\*(FIcommand\*(FC, \*(FIhow\*(FC)\*(FR
1268.br
1269close one end of co-process pipe.
1270Use \*(FC"to"\*(FR for the write end, or
1271\*(FC"from"\*(FR for the read end.\*(CD
1272.in -.2i
1273.sp .5
1274On success, \*(FCclose()\*(FR returns zero for a file, or the exit status for a process.
1275It returns \-1 if \*(FIfile\*(FR
1276was never opened, or
1277if there was a system problem.
1278\*(CB\*(FCERRNO\*(FR describes
1279the error.\*(CX
1280.EB "\s+2\f(HBCLOSING REDIRECTIONS\*(FR\s0"
1281
1282.BT
1283
1284.\" --- Printf Formats
1285.ES
1286.fi
1287\*(CDThe \*(FCprintf\fP statement and
1288\*(FCsprintf()\fP function
1289accept the following conversion specification formats:
1290.sp .5
1291.nf
1292\*(FC%c\fP an \s-1ASCII\s+1 character
1293\*(FC%d\fP a decimal number (the integer part)
1294\*(FC%i\fP a decimal number (the integer part)
1295\*(FC%e\fP a floating point number of the form
1296 \*(FC[\-]d.dddddde[+\^\-]dd\*(FR
1297\*(FC%E\fP like \*(FC%e\fP, but use \*(FCE\fP instead of \*(FCe\*(FR
1298\*(FC%f\fP a floating point number of the form
1299 \*(FC[\-]ddd.dddddd\*(FR
1300\*(FC%g\fP use \*(FC%e\fP or \*(FC%f\fP, whichever is shorter, with
1301 nonsignificant zeros suppressed
1302\*(FC%G\fP like \*(FC%g\fP, but use \*(FC%E\fP instead of \*(FC%e\*(FR
1303\*(FC%o\fP an unsigned octal integer
1304\*(FC%u\fP an unsigned decimal integer
1305\*(FC%s\fP a character string
1306\*(FC%x\fP an unsigned hexadecimal integer
1307\*(FC%X\fP like \*(FC%x\fP, but use \*(FCABCDEF\fP for 10\(en15
1308\*(FC%%\fP A literal \*(FC%\fP; no argument is converted
1309.sp .5
1310.fi
1311Optional, additional parameters may lie between the \*(FC%\fP
1312and the control letter:
1313.sp .5
1314.TS
1315expand;
1316l lw(2.2i).
1317\*(CB\*(FIcount\*(FC$\*(FR T{
1318use the
1319\*(FIcount\*(FR'th
1320argument at this point in the formatting
1321(a \*(FIpositional specifier\*(FR).
1322Use in translated versions of
1323format strings, not in the original text of an AWK program.\*(CD
1324T}
1325\*(FC\-\fP T{
1326left-justify the expression within its field.
1327T}
1328\*(FIspace\fP T{
1329for numeric conversions, prefix positive values
1330with a space and negative values with a
1331minus sign.
1332T}
1333\*(FC+\fP T{
1334used before the \*(FIwidth\fP modifier means to always
1335supply a sign for numeric conversions, even if
1336the data to be formatted is positive. The \*(FC+\fP
1337overrides the space modifier.
1338T}
1339\*(FC#\fP T{
1340use an ``alternate form'' for some control letters.
1341T}
1342 \*(FC%o\*(FR T{
1343supply a leading zero.
1344T}
1345 \*(FC%x\*(FR, \*(FC%X\*(FR T{
1346supply a leading \*(FC0x\*(FR or \*(FC0X\*(FR for a nonzero result.
1347T}
1348 \*(FC%e\*(FR, \*(FC%E\*(FR, \*(FC%f\*(FR T{
1349the result always has a decimal point.
1350T}
1351 \*(FC%g\*(FR, \*(FC%G\*(FR T{
1352trailing zeros are not removed.
1353T}
1354\*(FC0\fP T{
1355a leading zero acts as a flag, indicating output
1356should be padded with zeros instead of spaces.
1357This applies even to non-numeric output formats.
1358Only has an effect when the field width is wider
1359than the value to be printed.
1360T}
1361\*(FIwidth\fP T{
1362pad the field to this width. The field is normally
1363padded with spaces. If the \*(FC0\fP flag has been used,
1364pad with zeros.
1365T}
1366\*(FC.\*(FIprec\*(FR T{
1367precision.
1368The meaning of the \*(FIprec\*(FR varies by control letter:
1369T}
1370 \*(FC%d\*(FR, \*(FC%o\*(FR, \*(FC%i\*(FR,
1371 \*(FC%u\*(FR, \*(FC%x\*(FR, \*(FC%X\fP T{
1372the minimum number of digits to print.
1373T}
1374 \*(FC%e\*(FR, \*(FC%E\*(FR, \*(FC%f\*(FR T{
1375the number of digits to print to the right of the decimal point.
1376T}
1377 \*(FC%g\*(FR, \*(FC%G\fP T{
1378the maximum number of significant digits.
1379T}
1380 \*(FC%s\fP T{
1381the maximum number of characters to print.
1382T}
1383.TE
1384.sp .5
1385.fi
1386The dynamic \*(FIwidth\fP and \*(FIprec\fP capabilities of the ANSI C
1387\*(FCprintf()\fP routines are supported.
1388A \*(FC*\fP in place of either the \*(FIwidth\fP or \*(FIprec\fP
1389specifications causes their values to be taken from
1390the argument list to \*(FCprintf\fP or \*(FCsprintf()\*(FR.
1391\*(CBUse \*(FC*\*(FIn\*(FC$\*(FR to use positional specifiers
1392with a dynamic width or precision.\*(CX
1393.EB "\s+2\f(HBPRINTF FORMATS\*(FR\s0"
1394
1395
1396.BT
1397
1398.\" --- Special Filenames
1399.ES
1400.fi
1401\*(CDWhen doing I/O redirection from either \*(FCprint\fP
1402or \*(FCprintf\fP into a file or via \*(FCgetline\fP
1403from a file, all three implementations of \*(FCawk\fP
1404recognize certain special filenames internally. These filenames
1405allow access to open file descriptors inherited from the
1406parent process (usually the shell).
1407These filenames may also be used on the command line to name data files.
1408The filenames are:
1409.sp .5
1410.TS
1411expand;
1412l lw(2i).
1413\*(FC"\-"\fP standard input
1414\*(FC/dev/stdin\fP standard input \*(CR(not \*(MK)\*(CD
1415\*(FC/dev/stdout\fP standard output
1416\*(FC/dev/stderr\fP standard error output
1417.TE
1418.sp .5
1419.fi
1420\*(CBThe following names are specific to \*(GK.
1421.sp .5
1422.in +.2i
1423.ti -.2i
1424\*(FC/dev/fd/\^\*(FIn\*(FR
1425.br
1426File associated with the open file descriptor \*(FIn\*(FR.
1427.ti -.2i
1428\*(FC/inet/tcp/\*(FIlport\*(FC/\*(FIrhost\*(FC/\*(FIrport\*(FR
1429.br
1430File for TCP/IP connection on local port \*(FIlport\*(FR to
1431remote host \*(FIrhost\*(FR on remote port \*(FIrport\*(FR.
1432Use a port of \*(FC0\*(FR to have the system pick a port.
1433Usable only with the \*(FC|&\*(FR two-way I/O operator.
1434.ti -.2i
1435\*(FC/inet/udp/\*(FIlport\*(FC/\*(FIrhost\*(FC/\*(FIrport\*(FR
1436.br
1437Similar, but use UDP/IP instead of TCP/IP.
1438.ti -.2i
1439\*(CR\*(FC/inet/raw/\*(FIlport\*(FC/\*(FIrhost\*(FC/\*(FIrport\*(FR
1440.br
1441.\" Similar, but use raw IP sockets.
1442Reserved for future use.\*(CB
1443.in -.2i
1444.sp .5
1445.fi
1446Other special filenames provide access to information about the running
1447\*(FCgawk\fP process.
1448Reading from these files returns a single record.
1449The filenames and what they return are:\*(FR
1450.sp .5
1451.TS
1452expand;
1453l lw(2i).
1454\*(FC/dev/pid\fP process ID of current process
1455\*(FC/dev/ppid\fP parent process ID of current process
1456\*(FC/dev/pgrpid\fP process group ID of current process
1457\*(FC/dev/user\fP T{
1458.nf
1459a single newline-terminated record.
1460The fields are separated with spaces.
1461\*(FC$1\fP is the return value of \*(FIgetuid\*(FR(2),
1462\*(FC$2\fP is the return value of \*(FIgeteuid\*(FR(2),
1463\*(FC$3\fP is the return value of \*(FIgetgid\*(FR(2) , and
1464\*(FC$4\fP is the return value of \*(FIgetegid\*(FR(2).
1465.fi
1466Any additional fields are the group IDs returned
1467by \*(FIgetgroups\*(FR(2). Multiple groups may not be
1468supported on all systems.
1469T}
1470.TE
1471.sp .5
1472.fi
1473\*(CRThese filenames are now obsolete.
1474Use the \*(FCPROCINFO\fP array to obtain the information they provide.\*(CL
1475.EB "\s+2\f(HBSPECIAL FILENAMES\*(FR\s0"
1476.sp .5
1477.\" --- Builtin Numeric Functions
1478.ES
1479.fi
1480.TS
1481expand;
1482l lw(2i).
1483\*(CD\*(FCatan2(\*(FIy\*(FC, \*(FIx\*(FC)\*(FR the arctangent of \*(FIy/x\fP in radians.
1484\*(FCcos(\*(FIexpr\*(FC)\*(FR the cosine of \*(FIexpr\fP, which is in radians.
1485\*(FCexp(\*(FIexpr\*(FC)\*(FR the exponential function (\*(FIe \*(FC^ \*(FIx\*(FR).
1486\*(FCint(\*(FIexpr\*(FC)\*(FR truncates to integer.
1487\*(FClog(\*(FIexpr\*(FC)\*(FR the natural logarithm function (base \*(FIe\^\*(FR).
1488\*(FCrand()\fP a random number between 0 and 1 (0 \(<= \*(FIN\fP < 1).
1489\*(FCsin(\*(FIexpr\*(FC)\*(FR the sine of \*(FIexpr\fP, which is in radians.
1490\*(FCsqrt(\*(FIexpr\*(FC)\*(FR the square root function.
1491\&\*(FCsrand(\*(FR[\*(FIexpr\^\*(FR]\*(FC)\*(FR T{
1492uses \*(FIexpr\fP as a new seed for the random number
1493generator. If no \*(FIexpr\fP, the time of day is used.
1494Returns previous seed for the random number
1495generator.\*(CX
1496T}
1497.TE
1498.EB "\s+2\f(HBNUMERIC FUNCTIONS\*(FR\s0"
1499.sp .5
1500.\" --- Extensions
1501.ES
1502.fi
1503.in +.2i
1504.ti -.2i
1505\*(CD\*(FCextension(\*(FIlib\*(FC, \*(FIfunc\*(FC)\*(FR
1506.br
1507dynamically load the shared library
1508\*(FIlib\*(FR
1509and call
1510\*(FIfunc\*(FR
1511in it to initialize the library.
1512This adds new built-in functions to \*(GK.
1513It returns the value returned by
1514\*(FIfunc\*(FR.\*(CB
1515.in -.2i
1516.EB "\s+2\f(HBDYNAMIC EXTENSIONS (\*(GK\f(HB)\*(FR\s0"
1517
1518
1519.BT
1520
1521.\" --- Builtin String Functions
1522.ES
1523.fi
1524.in +.2i
1525.ti -.2i
1526\*(CB\*(FCasort(\*(FIs\*(FC \*(FR[\*(FC, \*(FId\*(FR]\*(FC)\*(FR
1527.br
1528sorts the source array \*(FIs\*(FR, replacing the indices with numeric
1529values 1 through \*(FIn\*(FR (the number of elements in the array),
1530and returns the number of elements.
1531If destination \*(FId\*(FR is supplied, \*(FIs\*(FR is copied to \*(FId\*(FR,
1532\*(FId\*(FR is sorted, and \*(FIs\*(FR is unchanged.\*(CD
1533.ti -.2i
1534\*(CB\*(FCasorti(\*(FIs\*(FC \*(FR[\*(FC, \*(FId\*(FR]\*(FC)\*(FR
1535.br
1536like \*(FCasort()\*(FR, but sorting is done on the indices, not
1537the values. The original values are thrown array, so provide a
1538second array to preserve the first.\*(CD
1539.ti -.2i
1540\*(CB\*(FCgensub(\*(FIr\*(FC, \*(FIs\*(FC, \*(FIh \*(FR[\*(FC, \*(FIt\*(FR]\*(FC)\*(FR
1541.br
1542search the target string
1543\*(FIt\fP for matches of the regular expression \*(FIr\*(FR. If
1544\*(FIh\fP is a string beginning with \*(FCg\fP or \*(FCG\*(FR,
1545replace all matches of \*(FIr\fP with \*(FIs\*(FR. Otherwise, \*(FIh\fP
1546is a number indicating which match of \*(FIr\fP to replace.
1547If \*(FIt\fP is not supplied, \*(FC$0\fP is used instead. Within the
1548replacement text \*(FIs\*(FR, the sequence \*(FC\e\*(FIn\*(FR,
1549where \*(FIn\fP is a digit from 1 to 9, may be used to indicate just
1550the text that matched the \*(FIn\*(FRth parenthesized subexpression.
1551The sequence \*(FC\e0\fP represents the entire matched text, as does
1552the character \*(FC&\*(FR. Unlike \*(FCsub()\fP and \*(FCgsub()\*(FR,
1553the modified string is returned as the result of the function,
1554and the original target string is \*(FInot\fP changed.\*(CD
1555.ti -.2i
1556\*(FCgsub(\*(FIr\*(FC, \*(FIs \*(FR[\*(FC, \*(FIt\*(FR]\*(FC)\*(FR
1557.br
1558for each substring matching the
1559regular expression \*(FIr\fP in the string \*(FIt\*(FR, substitute the
1560string \*(FIs\*(FR, and return the number of substitutions. If
1561\*(FIt\fP is not supplied, use \*(FC$0\*(FR. An \*(FC&\fP in the
1562replacement text is replaced with the text that was actually matched.
1563Use \*(FC\e&\fP to get a literal \*(FC&\*(FR. See \*(AM
1564for a fuller discussion of the rules for \*(FC&\*(FR's and backslashes
1565in the replacement text of \*(CB\*(FCgensub()\*(FR,\*(CD \*(FCsub()\*(FR
1566and \*(FCgsub()\*(FR
1567.ti -.2i
1568\*(FCindex(\*(FIs\*(FC, \*(FIt\*(FC)\*(FR
1569.br
1570returns the index of the string
1571\*(FIt\fP in the string \*(FIs\*(FR, or 0 if \*(FIt\fP is not present.
1572.ti -.2i
1573\*(FClength(\*(FR[\*(FIs\*(FR]\*(FC)\*(FR
1574.br
1575returns the length of the string
1576\*(FIs\*(FR, or the length of \*(FC$0\fP if \*(FIs\fP is not supplied.
1577\*(CBWith an array argument, returns the number of elements
1578in the array.\*(CD
1579.ti -.2i
1580\*(FCmatch(\*(FIs\*(FC, \*(FIr \*(CB\*(FR[\*(FC, \*(FIa\*(FR]\*(CD\*(FC)\*(FR
1581.br
1582returns the position in
1583\*(FIs\fP where the regular expression \*(FIr\fP occurs, or 0 if
1584\*(FIr\fP is not present, and sets the values of variables
1585\*(FCRSTART\fP
1586and \*(FCRLENGTH\*(FR.
1587\*(CBIf \*(FIa\*(FR is supplied, the text matching all of \*(FIr\*(FR
1588is placed in \*(FIa\*(FC[0]\*(FR. If there were parenthesized
1589subexpressions, the matching texts are placed
1590in \*(FIa\*(FC[1]\*(FR, \*(FIa\*(FC[2]\*(FR, and so on.
1591Subscripts
1592\*(FCa[\*(FIn\^\*(FC, "start"]\*(FR,
1593and
1594\*(FCa[\*(FIn\^\*(FC, "length"]\*(FR
1595provide the starting index in the string and length
1596respectively, of each matching substring.\*(CD
1597.ti -.2i
1598\*(FCsplit(\*(FIs\*(FC, \*(FIa \*(FR[\*(FC, \*(FIr\*(FR]\*(FC)\*(FR
1599.br
1600splits the string
1601\*(FIs\fP into the array \*(FIa\fP using the regular expression \*(FIr\*(FR,
1602and returns the number of fields. If \*(FIr\fP is omitted, \*(FCFS\fP
1603is used instead. The array \*(FIa\fP is cleared first.
1604Splitting behaves identically to field splitting.
1605(See \fHFields\fP, above.)
1606.ti -.2i
1607\*(FCsprintf(\*(FIfmt\*(FC, \*(FIexpr-list\*(FC)\*(FR
1608.br
1609prints \*(FIexpr-list\fP
1610according to \*(FIfmt\*(FR, and returns the resulting string.
1611.ti -.2i
1612\*(CB\*(FCstrtonum(\*(FIs\*(FC)\*(FR
1613.br
1614examines \*(FIs\*(FR, and returns its numeric value.
1615If \*(FIs\*(FR begins with a leading \*(FC0\*(FR,
1616\*(FCstrtonum()\*(FR assumes that \*(FIs\*(FR
1617is an octal number.
1618If \*(FIs\*(FR begins with a leading \*(FC0x\*(FR
1619or \*(FC0X\*(FR, \*(FCstrtonum()\*(FR assumes that
1620\*(FIs\*(FR is a hexadecimal number.\*(CD
1621.ti -.2i
1622\*(FCsub(\*(FIr\*(FC, \*(FIs \*(FR[\*(FC, \*(FIt\*(FR]\*(FC)\*(FR
1623.br
1624just like
1625\*(FCgsub()\*(FR, but only the first matching substring is replaced.\*(CX
1626.in -.2i
1627.EB "\s+2\f(HBSTRING FUNCTIONS\*(FR\s0"
1628
1629.BT
1630
1631.\" --- Builtin String Functions
1632.ES
1633.fi
1634.in +.2i
1635.ti -.2i
1636\*(CD\*(FCsubstr(\*(FIs\*(FC, \*(FIi \*(FR[\*(FC, \*(FIn\*(FR]\*(FC)\*(FR
1637.br
1638returns the at most
1639\*(FIn\*(FR-character substring of \*(FIs\fP starting at \*(FIi\*(FR.
1640If \*(FIn\fP is omitted, the rest of \*(FIs\fP is used.
1641.ti -.2i
1642\*(FCtolower(\*(FIstr\*(FC)\*(FR
1643.br
1644returns a copy of the string \*(FIstr\*(FR,
1645with all the upper-case characters in \*(FIstr\fP translated to their
1646corresponding lower-case counterparts. Non-alphabetic characters are
1647left unchanged.
1648.ti -.2i
1649\*(FCtoupper(\*(FIstr\*(FC)\*(FR
1650.br
1651returns a copy of the string \*(FIstr\*(FR,
1652with all the lower-case characters in \*(FIstr\fP translated to their
1653corresponding upper-case counterparts. Non-alphabetic characters are
1654left unchanged.\*(CX
1655.in -.2i
1656.EB "\s+2\f(HBSTRING FUNCTIONS (continued)\*(FR\s0"
1657
1658.\" --- Builtin Time Functions
1659.ES
1660.fi
1661\*(CD\*(GK
1662provides the following functions for obtaining time stamps and
1663formatting them.
1664.sp .5
1665.fi
1666.in +.2i
1667.ti -.2i
1668\*(FCmktime(\*(FIdatespec\*(FC)\*(FR
1669.br
1670turns \*(FIdatespec\fP into a time
1671stamp of the same form as returned by \*(FCsystime()\*(FR.
1672The \*(FIdatespec\fP is a string of the form
1673\*(FC"\*(FIYYYY MM DD HH MM SS[ DST]\*(FC"\*(FR.
1674.ti -.2i
1675\*(FCstrftime(\*(FR[\*(FIformat \*(FR[\*(FC, \*(FItimestamp\*(FR]]\*(FC)\*(FR
1676.br
1677formats \*(FItimestamp\fP
1678according to the specification in \*(FIformat\*(FR. The
1679\*(FItimestamp\fP should be of the same form as returned by
1680\*(FCsystime()\*(FR.
1681If \*(FItimestamp\fP is missing, the current time of day is used. If
1682\*(FIformat\fP is missing, a default format equivalent to the output
1683of \*(FIdate\*(FR(1) is used.
1684.ti -.2i
1685\*(FCsystime()\fP
1686.br
1687returns the current time of day as the number of
1688seconds since the Epoch.\*(CB
1689.in -.2i
1690.EB "\s+2\f(HBTIME FUNCTIONS (\*(GK\f(HB)\*(FR\s0"
1691
1692.\" --- Builtin Bit Manipulation Functions
1693.ES
1694.fi
1695\*(CD\*(GK
1696provides the following functions for doing bitwise operations.
1697.sp .5
1698.fi
1699.in +.2i
1700.ti -.2i
1701\*(FCand(\*(FIv1\*(FC, \*(FIv2\*(FC)\*(FR
1702.br
1703returns the bitwise AND of the values provided by
1704\*(FIv1\*(FR and \*(FIv2\*(FR.
1705.ti -.2i
1706\*(FCcompl(\*(FIval\*(FC)\*(FR
1707.br
1708returns the bitwise complement of
1709\*(FIval\*(FR.
1710.ti -.2i
1711\*(FClshift(\*(FIval\*(FC, \*(FIcount\*(FC)\*(FR
1712.br
1713returns the value of \*(FIval\*(FR,
1714shifted left by \*(FIcount\*(FR bits.
1715.ti -.2i
1716\*(FCor(\*(FIv1\*(FC, \*(FIv2\*(FC)\*(FR
1717.br
1718returns the bitwise OR of the values provided by
1719\*(FIv1\*(FR and \*(FIv2\*(FR.
1720.ti -.2i
1721\*(FCrshift(\*(FIval\*(FC, \*(FIcount\*(FC)\*(FR
1722.br
1723returns the value of \*(FIval\*(FR,
1724shifted right by \*(FIcount\*(FR bits.
1725.ti -.2i
1726\*(FCxor(\*(FIv1\*(FC, \*(FIv2\*(FC)\*(FR
1727.br
1728teturns the bitwise XOR of the values provided by
1729\*(FIv1\*(FR and \*(FIv2\*(FR.\*(CB
1730.in -.2i
1731.EB "\s+2\f(HBBIT MANIPULATION FUNCTIONS (\*(GK\f(HB)\*(FR\s0"
1732
1733.\" --- Environment Variables
1734.ES
1735.fi
1736\*(CDThe environment variable \*(FCAWKPATH\fP specifies a search path to use
1737when finding source files named with the \*(FC\-f\fP
1738option.
1739The default path is
1740\*(FC".:/usr/local/share/awk"\*(FR.
1741.\" if this variable does not exist.
1742.\" (The actual directory may vary,
1743.\" depending upon how \*(GK was built and installed.)
1744If a file name given to the \*(FC\-f\fP option contains a ``/'' character,
1745no path search is performed.
1746.sp .5
1747If \*(FCPOSIXLY_CORRECT\fP exists
1748.\" in the environment,
1749then \*(GK
1750behaves exactly as if the \*(FC\-\^\-posix\fP option had been given.\*(CB
1751.EB "\s+2\f(HBENVIRONMENT VARIABLES (\*(GK\f(HB)\*(FR\s0"
1752
1753.BT
1754
1755.\" --- User-defined Functions
1756.ES
1757.fi
1758\*(CDFunctions in AWK are defined as follows:
1759.sp .5
1760.nf
1761 \*(FCfunction \*(FIname\*(FC(\*(FIparameter list\*(FC)
1762 {
1763 \*(FIstatements
1764 \*(FC}\*(FR
1765.sp .5
1766.fi
1767Functions are executed when they are called from within expressions
1768in either patterns or actions. Actual parameters supplied in the function
1769call instantiate the formal parameters declared in the function.
1770Arrays are passed by reference, other variables are passed by value.
1771.sp .5
1772Local variables are declared as extra parameters
1773in the parameter list. The convention is to separate local variables from
1774real parameters by extra spaces in the parameter list. For example:
1775.sp .5
1776.nf
1777 \*(FC# a and b are local
1778 function f(p, q, a, b)
1779 {
1780 \&.....
1781 }
1782.sp .3
1783 /abc/ { ... ; f(1, 2) ; ... }\*(FR
1784.fi
1785.sp .5
1786The left parenthesis in a function call is required
1787to immediately follow the function name
1788without any intervening white space.
1789This is to avoid a syntactic ambiguity with the concatenation operator.
1790This restriction does not apply to the built-in functions.
1791.sp .5
1792Functions may call each other and may be recursive.
1793Function parameters used as local variables are initialized
1794to the null string and the number zero upon function invocation.
1795.sp .5
1796Use \*(FCreturn\fP to return a value from a function. The return value
1797is undefined if no value is provided, or if the function returns by
1798``falling off'' the end.
1799.sp .5
1800\*(CLThe word
1801\*(FCfunc\fP
1802may be used in place of
1803\*(FCfunction\*(FR.
1804\*(CRNote: This usage is deprecated.\*(CX
1805.EB "\s+2\f(HBUSER-DEFINED FUNCTIONS\*(FR\s0"
1806
1807.\" --- Localization
1808.ES
1809.fi
1810\*(CDThere are several steps involved in producing and running a localizable
1811\*(AK program.
1812.sp .5
18131. Add a \*(FCBEGIN\*(FR action to assign a value to the
1814\*(FCTEXTDOMAIN\*(FR variable to set the text domain for
1815your program.
1816.sp .5
1817.ti +5n
1818\*(FCBEGIN { TEXTDOMAIN = "myprog" }\*(FR
1819.sp .5
1820This allows \*(GK to find the \*(FC\&.mo\*(FR
1821file associated with your program.
1822Without this step, \*(GK uses the \*(FCmessages\*(FR text domain,
1823which probably won't work.
1824.sp .5
18252. Mark all strings that should be translated with leading underscores.
1826.sp .5
18273. Use the
1828\*(FCbindtextdomain()\*(FR,
1829\*(FCdcgettext()\*(FR,
1830and/or
1831\*(FCdcngettext()\*(FR
1832functions in your program, as appropriate.
1833.sp .5
18344. Run
1835.sp .5
1836.ti +5n
1837\*(FCgawk \-\^\-gen\-po \-f myprog.awk > myprog.po\*(FR
1838.sp .5
1839to generate a \*(FC\&.po\*(FR
1840file for your program.
1841.sp .5
18425. Provide appropriate translations, and build and install a corresponding
1843\*(FC\&.mo\*(FR file.
1844.sp .5
1845The internationalization features are described in full detail in \*(AM.\*(CB
1846.EB "\s+2\f(HBLOCALIZATION (\*(GK\f(HB)\*(FR\s0"
1847
1848
1849.BT
1850
1851.\" --- Builtin Internationalization Functions
1852.ES
1853.fi
1854\*(CD\*(GK
1855provides the following functions for runtime message translation.
1856.in +.2i
1857.sp .5
1858.ti -.2i
1859\*(FCbindtextdomain(\*(FIdirectory \*(FR[\*(FC, \*(FIdomain\*(FR]\*(FC)\*(FR
1860.br
1861specifies the directory where \*(GK looks for the \*(FC\&.mo\*(FR
1862files, in case they
1863will not or cannot be placed in the ``standard'' locations
1864(e.g., during testing.)
1865It returns the directory where \*(FIdomain\*(FR is ``bound.''
1866.sp .5
1867The default \*(FIdomain\*(FR is the value of \*(FCTEXTDOMAIN\*(FR.
1868When \*(FIdirectory\*(FR is the null string (\*(FC"\^"\*(FR),
1869\*(FCbindtextdomain()\*(FR returns the current binding for the
1870given \*(FIdomain\*(FR.
1871.ti -.2i
1872\*(FCdcgettext(\*(FIstring \*(FR[\*(FC, \*(FIdomain \*(FR[\*(FC, \*(FIcategory\*(FR]]\*(FC)\*(FR
1873.br
1874returns the translation of \*(FIstring\*(FR in text domain
1875\*(FIdomain\*(FR for locale category \*(FIcategory\*(FR.
1876The default value for \*(FIdomain\*(FR is the current value of \*(FCTEXTDOMAIN\*(FR.
1877The default value for \*(FIcategory\*(FR is \*(FC"LC_MESSAGES"\*(FR.
1878.sp .5
1879If you supply a value for \*(FIcategory\*(FR, it must be a string equal to
1880one of the known locale categories.
1881You must also supply a text domain. Use \*(FCTEXTDOMAIN\*(FR
1882to use the current domain.
1883.ti -.2i
1884\*(FCdcngettext(\*(FIstring1\*(FC, \*(FIstring2\*(FC, \*(FInumber\*(FR [\*(FC, \*(FIdom \*(FR[\*(FC, \*(FIcat\*(FR]]\*(FC)\*(FR
1885.br
1886returns the plural form used for \*(FInumber\*(FR of the translation of
1887\*(FIstring1\*(FR and \*(FIstring2\*(FR in text domain
1888\*(FIdom\*(FR for locale category \*(FIcat\*(FR.
1889The default value for \*(FIdom\*(FR is the current value of \*(FCTEXTDOMAIN\*(FR.
1890\*(FC"LC_MESSAGES"\*(FR
1891is the default value for \*(FIcat\*(FR.
1892.sp .5
1893If you supply a value for \*(FIcat\*(FR, it must be a string equal to
1894one of the known locale categories.
1895You must also supply a text domain. Use \*(FCTEXTDOMAIN\*(FR
1896to use the current domain.\*(CB
1897.in -.2i
1898.EB "\s+2\f(HBINTERNATIONALIZATION (\*(GK\f(HB)\*(FR\s0"
1899
1900
1901.\" --- FTP/HTTP Information
1902.ES
1903.nf
1904\*(CDHost: \*(FCftp.gnu.org\*(FR
1905File: \*(FC/gnu/gawk/gawk-3.1.5.tar.gz\fP
1906.in +.2i
1907.fi
1908GNU \*(AK (\*(GK). There may be a later version.
1909.in -.2i
1910.nf
1911.sp .5
1912\*(FChttp://cm.bell-labs.com/who/bwk/awk.tar.gz\fP
1913.in +.2i
1914.fi
1915\*(NK. This version requires an ANSI C compiler;
1916GCC (the GNU Compiler Collection) works well.
1917.in -.2i
1918.nf
1919.sp .5
1920Host: \*(FCftp.whidbey.net\*(FR
1921File: \*(FC/pub/brennan/mawk1.3.3.tar.gz\fP
1922.in +.2i
1923.fi
1924Michael Brennan's \*(MK. There may be a newer version.\*(CX
1925.in -.2i
1926.EB "\s+2\f(HBFTP/HTTP INFORMATION\*(FR\s0"
1927
1928
1929.\" --- Copying Permissions
1930.ES
1931.fi
1932\*(CDCopyright \(co 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
1933Free Software Foundation, Inc.
1934.sp .5
1935Permission is granted to make and distribute verbatim copies of this
1936reference card provided the copyright notice and this permission notice
1937are preserved on all copies.
1938.sp .5
1939Permission is granted to copy and distribute modified versions of this
1940reference card under the conditions for verbatim copying, provided that
1941the entire resulting derived work is distributed under the terms of a
1942permission notice identical to this one.
1943.sp .5
1944Permission is granted to copy and distribute translations of this
1945reference card into another language, under the above conditions for
1946modified versions, except that this permission notice may be stated in a
1947translation approved by the Foundation.\*(CX
1948.EB "\s+2\f(HBCOPYING PERMISSIONS\*(FR\s0"
1949.BT
Note: See TracBrowser for help on using the repository browser.