Initial import from FreeBSD RELENG_4:
[games.git] / contrib / awk / doc / awk.1
1 .\" $FreeBSD: src/contrib/awk/doc/awk.1,v 1.5 1999/09/27 08:57:04 sheldonh Exp $
2 .ds PX \s-1POSIX\s+1
3 .ds UX \s-1UNIX\s+1
4 .ds AN \s-1ANSI\s+1
5 .TH GAWK 1 "Apr 28 1999" "Free Software Foundation" "Utility Commands"
6 .SH NAME
7 gawk \- pattern scanning and processing language
8 .SH SYNOPSIS
9 .B gawk
10 [ POSIX or GNU style options ]
11 .B \-f
12 .I program-file
13 [
14 .B \-\^\-
15 ] file .\^.\^.
16 .br
17 .B gawk
18 [ POSIX or GNU style options ]
19 [
20 .B \-\^\-
21 ]
22 .I program-text
23 file .\^.\^.
24 .SH DESCRIPTION
25 .I Gawk
26 is the GNU Project's implementation of the AWK programming language.
27 It conforms to the definition of the language in
28 the \*(PX 1003.2 Command Language And Utilities Standard.
29 This version in turn is based on the description in
30 .IR "The AWK Programming Language" ,
31 by Aho, Kernighan, and Weinberger,
32 with the additional features found in the System V Release 4 version
33 of \*(UX
34 .IR awk .
35 .I Gawk
36 also provides more recent Bell Labs
37 .I awk
38 extensions, and some GNU-specific extensions.
39 .PP
40 The command line consists of options to
41 .I gawk
42 itself, the AWK program text (if not supplied via the
43 .B \-f
44 or
45 .B \-\^\-file
46 options), and values to be made
47 available in the
48 .B ARGC
49 and
50 .B ARGV
51 pre-defined AWK variables.
52 .SH OPTION FORMAT
53 .PP
54 .I Gawk
55 options may be either the traditional \*(PX one letter options,
56 or the GNU style long options.  \*(PX options start with a single ``\-'',
57 while long options start with ``\-\^\-''.
58 Long options are provided for both GNU-specific features and
59 for \*(PX mandated features.
60 .PP
61 Following the \*(PX standard,
62 .IR gawk -specific
63 options are supplied via arguments to the
64 .B \-W
65 option.  Multiple
66 .B \-W
67 options may be supplied
68 Each
69 .B \-W
70 option has a corresponding long option, as detailed below.
71 Arguments to long options are either joined with the option
72 by an
73 .B =
74 sign, with no intervening spaces, or they may be provided in the
75 next command line argument.
76 Long options may be abbreviated, as long as the abbreviation
77 remains unique.
78 .SH OPTIONS
79 .PP
80 .I Gawk
81 accepts the following options.
82 .TP
83 .PD 0
84 .BI \-F " fs"
85 .TP
86 .PD
87 .BI \-\^\-field-separator " fs"
88 Use
89 .I fs
90 for the input field separator (the value of the
91 .B FS
92 predefined
93 variable).
94 .TP
95 .PD 0
96 \fB\-v\fI var\fB\^=\^\fIval\fR
97 .TP
98 .PD
99 \fB\-\^\-assign \fIvar\fB\^=\^\fIval\fR
100 Assign the value
101 .IR val ,
102 to the variable
103 .IR var ,
104 before execution of the program begins.
105 Such variable values are available to the
106 .B BEGIN
107 block of an AWK program.
108 .TP
109 .PD 0
110 .BI \-f " program-file"
111 .TP
112 .PD
113 .BI \-\^\-file " program-file"
114 Read the AWK program source from the file
115 .IR program-file ,
116 instead of from the first command line argument.
117 Multiple
118 .B \-f
119 (or
120 .BR \-\^\-file )
121 options may be used.
122 .TP
123 .PD 0
124 .BI \-mf " NNN"
125 .TP
126 .PD
127 .BI \-mr " NNN"
128 Set various memory limits to the value
129 .IR NNN .
130 The
131 .B f
132 flag sets the maximum number of fields, and the
133 .B r
134 flag sets the maximum record size.  These two flags and the
135 .B \-m
136 option are from the Bell Labs research version of \*(UX
137 .IR awk .
138 They are ignored by
139 .IR gawk ,
140 since
141 .I gawk
142 has no pre-defined limits.
143 .TP
144 .PD 0
145 .B "\-W traditional"
146 .TP
147 .PD 0
148 .B "\-W compat"
149 .TP
150 .PD 0
151 .B \-\^\-traditional
152 .TP
153 .PD
154 .B \-\^\-compat
155 Run in
156 .I compatibility
157 mode.  In compatibility mode,
158 .I gawk
159 behaves identically to \*(UX
160 .IR awk ;
161 none of the GNU-specific extensions are recognized.
162 The use of
163 .B \-\^\-traditional
164 is preferred over the other forms of this option.
165 See
166 .BR "GNU EXTENSIONS" ,
167 below, for more information.
168 .TP
169 .PD 0
170 .B "\-W copyleft"
171 .TP
172 .PD 0
173 .B "\-W copyright"
174 .TP
175 .PD 0
176 .B \-\^\-copyleft
177 .TP
178 .PD
179 .B \-\^\-copyright
180 Print the short version of the GNU copyright information message on
181 the standard output, and exits successfully.
182 .TP
183 .PD 0
184 .B "\-W help"
185 .TP
186 .PD 0
187 .B "\-W usage"
188 .TP
189 .PD 0
190 .B \-\^\-help
191 .TP
192 .PD
193 .B \-\^\-usage
194 Print a relatively short summary of the available options on
195 the standard output.
196 (Per the
197 .IR "GNU Coding Standards" ,
198 these options cause an immediate, successful exit.)
199 .TP
200 .PD 0
201 .B "\-W lint"
202 .TP
203 .PD
204 .B \-\^\-lint
205 Provide warnings about constructs that are
206 dubious or non-portable to other AWK implementations.
207 .TP
208 .PD 0
209 .B "\-W lint\-old"
210 .TP
211 .PD
212 .B \-\^\-lint\-old
213 Provide warnings about constructs that are
214 not portable to the original version of Unix
215 .IR awk .
216 .ig
217 .\" This option is left undocumented, on purpose.
218 .TP
219 .PD 0
220 .B "\-W nostalgia"
221 .TP
222 .PD
223 .B \-\^\-nostalgia
224 Provide a moment of nostalgia for long time
225 .I awk
226 users.
227 ..
228 .TP
229 .PD 0
230 .B "\-W posix"
231 .TP
232 .PD
233 .B \-\^\-posix
234 This turns on
235 .I compatibility 
236 mode, with the following additional restrictions:
237 .RS
238 .TP \w'\(bu'u+1n
239 \(bu
240 .B \ex
241 escape sequences are not recognized.
242 .TP
243 \(bu
244 Only space and tab act as field separators when
245 .B FS
246 is set to a single space, newline does not.
247 .TP
248 \(bu
249 The synonym
250 .B func
251 for the keyword
252 .B function
253 is not recognized.
254 .TP
255 \(bu
256 The operators
257 .B **
258 and
259 .B **=
260 cannot be used in place of
261 .B ^
262 and
263 .BR ^= .
264 .TP
265 \(bu
266 The
267 .B fflush()
268 function is not available.
269 .RE
270 .TP
271 .PD 0
272 .B "\-W re\-interval"
273 .TP
274 .PD
275 .B \-\^\-re\-interval
276 Enable the use of
277 .I "interval expressions"
278 in regular expression matching
279 (see
280 .BR "Regular Expressions" ,
281 below).
282 Interval expressions were not traditionally available in the
283 AWK language. The POSIX standard added them, to make
284 .I awk
285 and
286 .I egrep
287 consistent with each other.
288 However, their use is likely
289 to break old AWK programs, so
290 .I gawk
291 only provides them if they are requested with this option, or when
292 .B \-\^\-posix
293 is specified.
294 .TP
295 .PD 0
296 .BI "\-W source " program-text
297 .TP
298 .PD
299 .BI \-\^\-source " program-text"
300 Use
301 .I program-text
302 as AWK program source code.
303 This option allows the easy intermixing of library functions (used via the 
304 .B \-f
305 and
306 .B \-\^\-file
307 options) with source code entered on the command line.
308 It is intended primarily for medium to large AWK programs used
309 in shell scripts.
310 .TP
311 .PD 0
312 .B "\-W version"
313 .TP
314 .PD
315 .B \-\^\-version
316 Print version information for this particular copy of
317 .I gawk
318 on the standard output.
319 This is useful mainly for knowing if the current copy of
320 .I gawk
321 on your system
322 is up to date with respect to whatever the Free Software Foundation
323 is distributing.
324 This is also useful when reporting bugs.
325 (Per the
326 .IR "GNU Coding Standards" ,
327 these options cause an immediate, successful exit.)
328 .TP
329 .B \-\^\-
330 Signal the end of options. This is useful to allow further arguments to the
331 AWK program itself to start with a ``\-''.
332 This is mainly for consistency with the argument parsing convention used
333 by most other \*(PX programs.
334 .PP
335 In compatibility mode,
336 any other options are flagged as illegal, but are otherwise ignored.
337 In normal operation, as long as program text has been supplied, unknown
338 options are passed on to the AWK program in the
339 .B ARGV
340 array for processing.  This is particularly useful for running AWK
341 programs via the ``#!'' executable interpreter mechanism.
342 .SH AWK PROGRAM EXECUTION
343 .PP
344 An AWK program consists of a sequence of pattern-action statements
345 and optional function definitions.
346 .RS
347 .PP
348 \fIpattern\fB   { \fIaction statements\fB }\fR
349 .br
350 \fBfunction \fIname\fB(\fIparameter list\fB) { \fIstatements\fB }\fR
351 .RE
352 .PP
353 .I Gawk
354 first reads the program source from the
355 .IR program-file (s)
356 if specified,
357 from arguments to
358 .BR \-\^\-source ,
359 or from the first non-option argument on the command line.
360 The
361 .B \-f
362 and
363 .B \-\^\-source
364 options may be used multiple times on the command line.
365 .I Gawk
366 will read the program text as if all the
367 .IR program-file s
368 and command line source texts
369 had been concatenated together.  This is useful for building libraries
370 of AWK functions, without having to include them in each new AWK
371 program that uses them.  It also provides the ability to mix library
372 functions with command line programs.
373 .PP
374 The environment variable
375 .B AWKPATH
376 specifies a search path to use when finding source files named with
377 the 
378 .B \-f
379 option.  If this variable does not exist, the default path is
380 \fB".:/usr/local/share/awk"\fR.
381 (The actual directory may vary, depending upon how
382 .I gawk
383 was built and installed.)
384 If a file name given to the
385 .B \-f
386 option contains a ``/'' character, no path search is performed.
387 .PP
388 .I Gawk
389 executes AWK programs in the following order.
390 First,
391 all variable assignments specified via the
392 .B \-v
393 option are performed.
394 Next,
395 .I gawk
396 compiles the program into an internal form.
397 Then,
398 .I gawk
399 executes the code in the
400 .B BEGIN
401 block(s) (if any),
402 and then proceeds to read
403 each file named in the
404 .B ARGV
405 array.
406 If there are no files named on the command line,
407 .I gawk
408 reads the standard input.
409 .PP
410 If a filename on the command line has the form
411 .IB var = val
412 it is treated as a variable assignment. The variable
413 .I var
414 will be assigned the value
415 .IR val .
416 (This happens after any
417 .B BEGIN
418 block(s) have been run.)
419 Command line variable assignment
420 is most useful for dynamically assigning values to the variables
421 AWK uses to control how input is broken into fields and records. It
422 is also useful for controlling state if multiple passes are needed over
423 a single data file.
424 .PP
425 If the value of a particular element of
426 .B ARGV
427 is empty (\fB""\fR),
428 .I gawk
429 skips over it.
430 .PP
431 For each record in the input,
432 .I gawk
433 tests to see if it matches any
434 .I pattern
435 in the AWK program.
436 For each pattern that the record matches, the associated
437 .I action
438 is executed.
439 The patterns are tested in the order they occur in the program.
440 .PP
441 Finally, after all the input is exhausted,
442 .I gawk
443 executes the code in the
444 .B END
445 block(s) (if any).
446 .SH VARIABLES, RECORDS AND FIELDS
447 AWK variables are dynamic; they come into existence when they are
448 first used. Their values are either floating-point numbers or strings,
449 or both,
450 depending upon how they are used. AWK also has one dimensional
451 arrays; arrays with multiple dimensions may be simulated.
452 Several pre-defined variables are set as a program
453 runs; these will be described as needed and summarized below.
454 .SS Records
455 Normally, records are separated by newline characters. You can control how
456 records are separated by assigning values to the built-in variable
457 .BR RS .
458 If 
459 .B RS
460 is any single character, that character separates records.
461 Otherwise,
462 .B RS
463 is a regular expression.  Text in the input that matches this
464 regular expression will separate the record.
465 However, in compatibility mode,
466 only the first character of its string
467 value is used for separating records.
468 If
469 .B RS
470 is set to the null string, then records are separated by
471 blank lines.
472 When
473 .B RS
474 is set to the null string, the newline character always acts as
475 a field separator, in addition to whatever value
476 .B FS
477 may have.
478 .SS Fields
479 .PP
480 As each input record is read,
481 .I gawk
482 splits the record into
483 .IR fields ,
484 using the value of the
485 .B FS
486 variable as the field separator.
487 If
488 .B FS
489 is a single character, fields are separated by that character.
490 If
491 .B FS
492 is the null string, then each individual character becomes a
493 separate field.
494 Otherwise,
495 .B FS
496 is expected to be a full regular expression.
497 In the special case that
498 .B FS
499 is a single space, fields are separated
500 by runs of spaces and/or tabs and/or newlines.
501 (But see the discussion of
502 .BR \-\-posix ,
503 below).
504 Note that the value of
505 .B IGNORECASE
506 (see below) will also affect how fields are split when
507 .B FS
508 is a regular expression, and how records are separated when
509 .B RS
510 is a regular expression.
511 .PP
512 If the
513 .B FIELDWIDTHS
514 variable is set to a space separated list of numbers, each field is
515 expected to have fixed width, and
516 .I gawk
517 will split up the record using the specified widths.  The value of
518 .B FS
519 is ignored.
520 Assigning a new value to
521 .B FS
522 overrides the use of
523 .BR FIELDWIDTHS ,
524 and restores the default behavior.
525 .PP
526 Each field in the input record may be referenced by its position,
527 .BR $1 ,
528 .BR $2 ,
529 and so on.
530 .B $0
531 is the whole record. The value of a field may be assigned to as well.
532 Fields need not be referenced by constants:
533 .RS
534 .PP
535 .ft B
536 n = 5
537 .br
538 print $n
539 .ft R
540 .RE
541 .PP
542 prints the fifth field in the input record.
543 The variable
544 .B NF
545 is set to the total number of fields in the input record.
546 .PP
547 References to non-existent fields (i.e. fields after
548 .BR $NF )
549 produce the null-string. However, assigning to a non-existent field
550 (e.g., 
551 .BR "$(NF+2) = 5" )
552 will increase the value of
553 .BR NF ,
554 create any intervening fields with the null string as their value, and
555 cause the value of
556 .B $0
557 to be recomputed, with the fields being separated by the value of
558 .BR OFS .
559 References to negative numbered fields cause a fatal error.
560 Decrementing
561 .B NF
562 causes the values of fields past the new value to be lost, and the value of
563 .B $0
564 to be recomputed, with the fields being separated by the value of
565 .BR OFS .
566 .SS Built-in Variables
567 .PP
568 .IR Gawk 's
569 built-in variables are:
570 .PP
571 .TP \w'\fBFIELDWIDTHS\fR'u+1n
572 .B ARGC
573 The number of command line arguments (does not include options to
574 .IR gawk ,
575 or the program source).
576 .TP
577 .B ARGIND
578 The index in
579 .B ARGV
580 of the current file being processed.
581 .TP
582 .B ARGV
583 Array of command line arguments. The array is indexed from
584 0 to
585 .B ARGC
586 \- 1.
587 Dynamically changing the contents of
588 .B ARGV
589 can control the files used for data.
590 .TP
591 .B CONVFMT
592 The conversion format for numbers, \fB"%.6g"\fR, by default.
593 .TP
594 .B ENVIRON
595 An array containing the values of the current environment.
596 The array is indexed by the environment variables, each element being
597 the value of that variable (e.g., \fBENVIRON["HOME"]\fP might be
598 .BR /home/arnold ).
599 Changing this array does not affect the environment seen by programs which
600 .I gawk
601 spawns via redirection or the
602 .B system()
603 function.
604 (This may change in a future version of
605 .IR gawk .)
606 .\" but don't hold your breath...
607 .TP
608 .B ERRNO
609 If a system error occurs either doing a redirection for
610 .BR getline ,
611 during a read for
612 .BR getline ,
613 or during a
614 .BR close() ,
615 then
616 .B ERRNO
617 will contain
618 a string describing the error.
619 .TP
620 .B FIELDWIDTHS
621 A white-space separated list of fieldwidths.  When set,
622 .I gawk
623 parses the input into fields of fixed width, instead of using the
624 value of the
625 .B FS
626 variable as the field separator.
627 The fixed field width facility is still experimental; the
628 semantics may change as
629 .I gawk
630 evolves over time.
631 .TP
632 .B FILENAME
633 The name of the current input file.
634 If no files are specified on the command line, the value of
635 .B FILENAME
636 is ``\-''.
637 However,
638 .B FILENAME
639 is undefined inside the
640 .B BEGIN
641 block.
642 .TP
643 .B FNR
644 The input record number in the current input file.
645 .TP
646 .B FS
647 The input field separator, a space by default.  See
648 .BR Fields ,
649 above.
650 .TP
651 .B IGNORECASE
652 Controls the case-sensitivity of all regular expression 
653 and string operations. If
654 .B IGNORECASE
655 has a non-zero value, then string comparisons and
656 pattern matching in rules,
657 field splitting with
658 .BR FS ,
659 record separating with
660 .BR RS ,
661 regular expression
662 matching with
663 .B ~
664 and
665 .BR !~ ,
666 and the
667 .BR gensub() ,
668 .BR gsub() ,
669 .BR index() ,
670 .BR match() ,
671 .BR split() ,
672 and
673 .B sub()
674 pre-defined functions will all ignore case when doing regular expression
675 operations.  Thus, if
676 .B IGNORECASE
677 is not equal to zero,
678 .B /aB/
679 matches all of the strings \fB"ab"\fP, \fB"aB"\fP, \fB"Ab"\fP,
680 and \fB"AB"\fP.
681 As with all AWK variables, the initial value of
682 .B IGNORECASE
683 is zero, so all regular expression and string
684 operations are normally case-sensitive.
685 Under Unix, the full ISO 8859-1 Latin-1 character set is used
686 when ignoring case.
687 .B NOTE:
688 In versions of
689 .I gawk
690 prior to 3.0,
691 .B IGNORECASE
692 only affected regular expression operations. It now affects string
693 comparisons as well.
694 .TP
695 .B NF
696 The number of fields in the current input record.
697 .TP
698 .B NR
699 The total number of input records seen so far.
700 .TP
701 .B OFMT
702 The output format for numbers, \fB"%.6g"\fR, by default.
703 .TP
704 .B OFS
705 The output field separator, a space by default.
706 .TP
707 .B ORS
708 The output record separator, by default a newline.
709 .TP
710 .B RS
711 The input record separator, by default a newline.
712 .TP
713 .B RT
714 The record terminator.
715 .I Gawk
716 sets
717 .B RT
718 to the input text that matched the character or regular expression
719 specified by
720 .BR RS .
721 .TP
722 .B RSTART
723 The index of the first character matched by
724 .BR match() ;
725 0 if no match.
726 .TP
727 .B RLENGTH
728 The length of the string matched by
729 .BR match() ;
730 \-1 if no match.
731 .TP
732 .B SUBSEP
733 The character used to separate multiple subscripts in array
734 elements, by default \fB"\e034"\fR.
735 .SS Arrays
736 .PP
737 Arrays are subscripted with an expression between square brackets
738 .RB ( [ " and " ] ).
739 If the expression is an expression list
740 .RI ( expr ", " expr " ...)"
741 then the array subscript is a string consisting of the
742 concatenation of the (string) value of each expression,
743 separated by the value of the
744 .B SUBSEP
745 variable.
746 This facility is used to simulate multiply dimensioned
747 arrays. For example:
748 .PP
749 .RS
750 .ft B
751 i = "A";\^ j = "B";\^ k = "C"
752 .br
753 x[i, j, k] = "hello, world\en"
754 .ft R
755 .RE
756 .PP
757 assigns the string \fB"hello, world\en"\fR to the element of the array
758 .B x
759 which is indexed by the string \fB"A\e034B\e034C"\fR. All arrays in AWK
760 are associative, i.e. indexed by string values.
761 .PP
762 The special operator
763 .B in
764 may be used in an
765 .B if
766 or
767 .B while
768 statement to see if an array has an index consisting of a particular
769 value.
770 .PP
771 .RS
772 .ft B
773 .nf
774 if (val in array)
775         print array[val]
776 .fi
777 .ft
778 .RE
779 .PP
780 If the array has multiple subscripts, use
781 .BR "(i, j) in array" .
782 .PP
783 The
784 .B in
785 construct may also be used in a
786 .B for
787 loop to iterate over all the elements of an array.
788 .PP
789 An element may be deleted from an array using the
790 .B delete
791 statement.
792 The
793 .B delete
794 statement may also be used to delete the entire contents of an array,
795 just by specifying the array name without a subscript.
796 .SS Variable Typing And Conversion
797 .PP
798 Variables and fields
799 may be (floating point) numbers, or strings, or both. How the
800 value of a variable is interpreted depends upon its context. If used in
801 a numeric expression, it will be treated as a number, if used as a string
802 it will be treated as a string.
803 .PP
804 To force a variable to be treated as a number, add 0 to it; to force it
805 to be treated as a string, concatenate it with the null string.
806 .PP
807 When a string must be converted to a number, the conversion is accomplished
808 using
809 .IR atof (3).
810 A number is converted to a string by using the value of
811 .B CONVFMT
812 as a format string for
813 .IR sprintf (3),
814 with the numeric value of the variable as the argument.
815 However, even though all numbers in AWK are floating-point,
816 integral values are
817 .I always
818 converted as integers.  Thus, given
819 .PP
820 .RS
821 .ft B
822 .nf
823 CONVFMT = "%2.2f"
824 a = 12
825 b = a ""
826 .fi
827 .ft R
828 .RE
829 .PP
830 the variable
831 .B b
832 has a string value of \fB"12"\fR and not \fB"12.00"\fR.
833 .PP
834 .I Gawk
835 performs comparisons as follows:
836 If two variables are numeric, they are compared numerically.
837 If one value is numeric and the other has a string value that is a
838 ``numeric string,'' then comparisons are also done numerically.
839 Otherwise, the numeric value is converted to a string and a string
840 comparison is performed.
841 Two strings are compared, of course, as strings.
842 According to the \*(PX standard, even if two strings are
843 numeric strings, a numeric comparison is performed.  However, this is
844 clearly incorrect, and
845 .I gawk
846 does not do this.
847 .PP
848 Note that string constants, such as \fB"57"\fP, are
849 .I not
850 numeric strings, they are string constants.  The idea of ``numeric string''
851 only applies to fields,
852 .B getline
853 input,
854 .BR FILENAME ,
855 .B ARGV
856 elements,
857 .B ENVIRON
858 elements and the elements of an array created by
859 .B split()
860 that are numeric strings.
861 The basic idea is that
862 .IR "user input" ,
863 and only user input, that looks numeric,
864 should be treated that way.
865 .PP
866 Uninitialized variables have the numeric value 0 and the string value ""
867 (the null, or empty, string).
868 .SH PATTERNS AND ACTIONS
869 AWK is a line oriented language. The pattern comes first, and then the
870 action. Action statements are enclosed in
871 .B {
872 and
873 .BR } .
874 Either the pattern may be missing, or the action may be missing, but,
875 of course, not both. If the pattern is missing, the action will be
876 executed for every single record of input.
877 A missing action is equivalent to
878 .RS
879 .PP
880 .B "{ print }"
881 .RE
882 .PP
883 which prints the entire record.
884 .PP
885 Comments begin with the ``#'' character, and continue until the
886 end of the line.
887 Blank lines may be used to separate statements.
888 Normally, a statement ends with a newline, however, this is not the
889 case for lines ending in
890 a ``,'',
891 .BR { ,
892 .BR ? ,
893 .BR : ,
894 .BR && ,
895 or
896 .BR || .
897 Lines ending in
898 .B do
899 or
900 .B else
901 also have their statements automatically continued on the following line.
902 In other cases, a line can be continued by ending it with a ``\e'',
903 in which case the newline will be ignored.
904 .PP
905 Multiple statements may
906 be put on one line by separating them with a ``;''.
907 This applies to both the statements within the action part of a
908 pattern-action pair (the usual case),
909 and to the pattern-action statements themselves.
910 .SS Patterns
911 AWK patterns may be one of the following:
912 .PP
913 .RS
914 .nf
915 .B BEGIN
916 .B END
917 .BI / "regular expression" /
918 .I "relational expression"
919 .IB pattern " && " pattern
920 .IB pattern " || " pattern
921 .IB pattern " ? " pattern " : " pattern
922 .BI ( pattern )
923 .BI ! " pattern"
924 .IB pattern1 ", " pattern2
925 .fi
926 .RE
927 .PP
928 .B BEGIN
929 and
930 .B END
931 are two special kinds of patterns which are not tested against
932 the input.
933 The action parts of all
934 .B BEGIN
935 patterns are merged as if all the statements had
936 been written in a single
937 .B BEGIN
938 block. They are executed before any
939 of the input is read. Similarly, all the
940 .B END
941 blocks are merged,
942 and executed when all the input is exhausted (or when an
943 .B exit
944 statement is executed).
945 .B BEGIN
946 and
947 .B END
948 patterns cannot be combined with other patterns in pattern expressions.
949 .B BEGIN
950 and
951 .B END
952 patterns cannot have missing action parts.
953 .PP
954 For
955 .BI / "regular expression" /
956 patterns, the associated statement is executed for each input record that matches
957 the regular expression.
958 Regular expressions are the same as those in
959 .IR egrep (1),
960 and are summarized below.
961 .PP
962 A
963 .I "relational expression"
964 may use any of the operators defined below in the section on actions.
965 These generally test whether certain fields match certain regular expressions.
966 .PP
967 The
968 .BR && ,
969 .BR || ,
970 and
971 .B !
972 operators are logical AND, logical OR, and logical NOT, respectively, as in C.
973 They do short-circuit evaluation, also as in C, and are used for combining
974 more primitive pattern expressions. As in most languages, parentheses
975 may be used to change the order of evaluation.
976 .PP
977 The
978 .B ?\^:
979 operator is like the same operator in C. If the first pattern is true
980 then the pattern used for testing is the second pattern, otherwise it is
981 the third. Only one of the second and third patterns is evaluated.
982 .PP
983 The 
984 .IB pattern1 ", " pattern2
985 form of an expression is called a
986 .IR "range pattern" .
987 It matches all input records starting with a record that matches
988 .IR pattern1 ,
989 and continuing until a record that matches
990 .IR pattern2 ,
991 inclusive. It does not combine with any other sort of pattern expression.
992 .SS Regular Expressions
993 Regular expressions are the extended kind found in
994 .IR egrep .
995 They are composed of characters as follows:
996 .TP \w'\fB[^\fIabc...\fB]\fR'u+2n
997 .I c
998 matches the non-metacharacter
999 .IR c .
1000 .TP
1001 .I \ec
1002 matches the literal character
1003 .IR c .
1004 .TP
1005 .B .
1006 matches any character
1007 .I including
1008 newline.
1009 .TP
1010 .B ^
1011 matches the beginning of a string.
1012 .TP
1013 .B $
1014 matches the end of a string.
1015 .TP
1016 .BI [ abc... ]
1017 character list, matches any of the characters
1018 .IR abc... .
1019 .TP
1020 .BI [^ abc... ]
1021 negated character list, matches any character except
1022 .IR abc... .
1023 .TP
1024 .IB r1 | r2
1025 alternation: matches either
1026 .I r1
1027 or
1028 .IR r2 .
1029 .TP
1030 .I r1r2
1031 concatenation: matches
1032 .IR r1 ,
1033 and then
1034 .IR r2 .
1035 .TP
1036 .IB r +
1037 matches one or more
1038 .IR r 's. 
1039 .TP
1040 .IB r *
1041 matches zero or more
1042 .IR r 's. 
1043 .TP
1044 .IB r ?
1045 matches zero or one
1046 .IR r 's. 
1047 .TP
1048 .BI ( r )
1049 grouping: matches
1050 .IR r .
1051 .TP
1052 .PD 0
1053 .IB r { n }
1054 .TP
1055 .PD 0
1056 .IB r { n ,}
1057 .TP
1058 .PD
1059 .IB r { n , m }
1060 One or two numbers inside braces denote an
1061 .IR "interval expression" .
1062 If there is one number in the braces, the preceding regexp
1063 .I r
1064 is repeated
1065 .I n
1066 times.  If there are two numbers separated by a comma,
1067 .I r
1068 is repeated
1069 .I n
1070 to
1071 .I m
1072 times.
1073 If there is one number followed by a comma, then
1074 .I r
1075 is repeated at least
1076 .I n
1077 times.
1078 .sp .5
1079 Interval expressions are only available if either
1080 .B \-\^\-posix
1081 or
1082 .B \-\^\-re\-interval
1083 is specified on the command line.
1084 .TP
1085 .B \ey
1086 matches the empty string at either the beginning or the
1087 end of a word.
1088 .TP
1089 .B \eB
1090 matches the empty string within a word.
1091 .TP
1092 .B \e<
1093 matches the empty string at the beginning of a word.
1094 .TP
1095 .B \e>
1096 matches the empty string at the end of a word.
1097 .TP
1098 .B \ew
1099 matches any word-constituent character (letter, digit, or underscore).
1100 .TP
1101 .B \eW
1102 matches any character that is not word-constituent.
1103 .TP
1104 .B \e`
1105 matches the empty string at the beginning of a buffer (string).
1106 .TP
1107 .B \e'
1108 matches the empty string at the end of a buffer.
1109 .PP
1110 The escape sequences that are valid in string constants (see below)
1111 are also legal in regular expressions.
1112 .PP
1113 .I "Character classes"
1114 are a new feature introduced in the POSIX standard.
1115 A character class is a special notation for describing
1116 lists of characters that have a specific attribute, but where the 
1117 actual characters themselves can vary from country to country and/or
1118 from character set to character set.  For example, the notion of what
1119 is an alphabetic character differs in the USA and in France.
1120 .PP
1121 A character class is only valid in a regexp
1122 .I inside
1123 the brackets of a character list.  Character classes consist of
1124 .BR [: ,
1125 a keyword denoting the class, and
1126 .BR :] .
1127 Here are the character
1128 classes defined by the POSIX standard.
1129 .TP
1130 .B [:alnum:]
1131 Alphanumeric characters.
1132 .TP
1133 .B [:alpha:]
1134 Alphabetic characters.
1135 .TP
1136 .B [:blank:]
1137 Space or tab characters.
1138 .TP
1139 .B [:cntrl:]
1140 Control characters.
1141 .TP
1142 .B [:digit:]
1143 Numeric characters.
1144 .TP
1145 .B [:graph:]
1146 Characters that are both printable and visible.
1147 (A space is printable, but not visible, while an
1148 .B a
1149 is both.)
1150 .TP
1151 .B [:lower:]
1152 Lower-case alphabetic characters.
1153 .TP
1154 .B [:print:]
1155 Printable characters (characters that are not control characters.)
1156 .TP
1157 .B [:punct:]
1158 Punctuation characters (characters that are not letter, digits,
1159 control characters, or space characters).
1160 .TP
1161 .B [:space:]
1162 Space characters (such as space, tab, and formfeed, to name a few).
1163 .TP
1164 .B [:upper:]
1165 Upper-case alphabetic characters.
1166 .TP
1167 .B [:xdigit:]
1168 Characters that are hexadecimal digits.
1169 .PP
1170 For example, before the POSIX standard, to match alphanumeric
1171 characters, you would have had to write
1172 .BR /[A\-Za\-z0\-9]/ .
1173 If your character set had other alphabetic characters in it, this would not
1174 match them.  With the POSIX character classes, you can write
1175 .BR /[[:alnum:]]/ ,
1176 and this will match
1177 .I all
1178 the alphabetic and numeric characters in your character set.
1179 .PP
1180 Two additional special sequences can appear in character lists.
1181 These apply to non-ASCII character sets, which can have single symbols
1182 (called 
1183 .IR "collating elements" )
1184 that are represented with more than one
1185 character, as well as several characters that are equivalent for
1186 .IR collating ,
1187 or sorting, purposes.  (E.g., in French, a plain ``e''
1188 and a grave-accented e\` are equivalent.)
1189 .TP
1190 Collating Symbols
1191 A collating symbols is a multi-character collating element enclosed in
1192 .B [.
1193 and
1194 .BR .] .
1195 For example, if
1196 .B ch
1197 is a collating element, then
1198 .B [[.ch.]]
1199 is a regexp that matches this collating element, while
1200 .B [ch]
1201 is a regexp that matches either
1202 .B c
1203 or
1204 .BR h .
1205 .TP
1206 Equivalence Classes
1207 An equivalence class is a locale-specific name for a list of
1208 characters that are equivalent. The name is enclosed in
1209 .B [=
1210 and
1211 .BR =] .
1212 For example, the name
1213 .B e
1214 might be used to represent all of
1215 ``e,'' ``e\`,'' and ``e\`.''
1216 In this case,
1217 .B [[=e=]]
1218 is a regexp
1219 that matches any of
1220 .BR e ,
1221 .BR e\' ,
1222 or
1223 .BR e\` .
1224 .PP
1225 These features are very valuable in non-English speaking locales.
1226 The library functions that
1227 .I gawk
1228 uses for regular expression matching
1229 currently only recognize POSIX character classes; they do not recognize
1230 collating symbols or equivalence classes.
1231 .PP
1232 The
1233 .BR \ey ,
1234 .BR \eB ,
1235 .BR \e< ,
1236 .BR \e> ,
1237 .BR \ew ,
1238 .BR \eW ,
1239 .BR \e` ,
1240 and
1241 .B \e'
1242 operators are specific to
1243 .IR gawk ;
1244 they are extensions based on facilities in the GNU regexp libraries.
1245 .PP
1246 The various command line options
1247 control how
1248 .I gawk
1249 interprets characters in regexps.
1250 .TP
1251 No options
1252 In the default case,
1253 .I gawk
1254 provide all the facilities of
1255 POSIX regexps and the GNU regexp operators described above.
1256 However, interval expressions are not supported.
1257 .TP
1258 .B \-\^\-posix
1259 Only POSIX regexps are supported, the GNU operators are not special.
1260 (E.g.,
1261 .B \ew
1262 matches a literal
1263 .BR w ).
1264 Interval expressions are allowed.
1265 .TP
1266 .B \-\^\-traditional
1267 Traditional Unix
1268 .I awk
1269 regexps are matched. The GNU operators
1270 are not special, interval expressions are not available, and neither
1271 are the POSIX character classes
1272 .RB ( [[:alnum:]]
1273 and so on).
1274 Characters described by octal and hexadecimal escape sequences are
1275 treated literally, even if they represent regexp metacharacters.
1276 .TP
1277 .B \-\^\-re\-interval
1278 Allow interval expressions in regexps, even if
1279 .B \-\^\-traditional
1280 has been provided.
1281 .SS Actions
1282 Action statements are enclosed in braces,
1283 .B {
1284 and
1285 .BR } .
1286 Action statements consist of the usual assignment, conditional, and looping
1287 statements found in most languages. The operators, control statements,
1288 and input/output statements
1289 available are patterned after those in C.
1290 .SS Operators
1291 .PP
1292 The operators in AWK, in order of decreasing precedence, are
1293 .PP
1294 .TP "\w'\fB*= /= %= ^=\fR'u+1n"
1295 .BR ( \&... )
1296 Grouping
1297 .TP
1298 .B $
1299 Field reference.
1300 .TP
1301 .B "++ \-\^\-"
1302 Increment and decrement, both prefix and postfix.
1303 .TP
1304 .B ^
1305 Exponentiation (\fB**\fR may also be used, and \fB**=\fR for
1306 the assignment operator).
1307 .TP
1308 .B "+ \- !"
1309 Unary plus, unary minus, and logical negation.
1310 .TP
1311 .B "* / %"
1312 Multiplication, division, and modulus.
1313 .TP
1314 .B "+ \-"
1315 Addition and subtraction.
1316 .TP
1317 .I space
1318 String concatenation.
1319 .TP
1320 .PD 0
1321 .B "< >"
1322 .TP
1323 .PD 0
1324 .B "<= >="
1325 .TP
1326 .PD
1327 .B "!= =="
1328 The regular relational operators.
1329 .TP
1330 .B "~ !~"
1331 Regular expression match, negated match.
1332 .B NOTE:
1333 Do not use a constant regular expression
1334 .RB ( /foo/ )
1335 on the left-hand side of a
1336 .B ~
1337 or
1338 .BR !~ .
1339 Only use one on the right-hand side.  The expression
1340 .BI "/foo/ ~ " exp
1341 has the same meaning as \fB(($0 ~ /foo/) ~ \fIexp\fB)\fR.
1342 This is usually
1343 .I not
1344 what was intended.
1345 .TP
1346 .B in
1347 Array membership.
1348 .TP
1349 .B &&
1350 Logical AND.
1351 .TP
1352 .B ||
1353 Logical OR.
1354 .TP
1355 .B ?:
1356 The C conditional expression. This has the form
1357 .IB expr1 " ? " expr2 " : " expr3\c
1358 \&. If
1359 .I expr1
1360 is true, the value of the expression is
1361 .IR expr2 ,
1362 otherwise it is
1363 .IR expr3 .
1364 Only one of
1365 .I expr2
1366 and
1367 .I expr3
1368 is evaluated.
1369 .TP
1370 .PD 0
1371 .B "= += \-="
1372 .TP
1373 .PD
1374 .B "*= /= %= ^="
1375 Assignment. Both absolute assignment
1376 .BI ( var " = " value )
1377 and operator-assignment (the other forms) are supported.
1378 .SS Control Statements
1379 .PP
1380 The control statements are
1381 as follows:
1382 .PP
1383 .RS
1384 .nf
1385 \fBif (\fIcondition\fB) \fIstatement\fR [ \fBelse\fI statement \fR]
1386 \fBwhile (\fIcondition\fB) \fIstatement \fR
1387 \fBdo \fIstatement \fBwhile (\fIcondition\fB)\fR
1388 \fBfor (\fIexpr1\fB; \fIexpr2\fB; \fIexpr3\fB) \fIstatement\fR
1389 \fBfor (\fIvar \fBin\fI array\fB) \fIstatement\fR
1390 \fBbreak\fR
1391 \fBcontinue\fR
1392 \fBdelete \fIarray\^\fB[\^\fIindex\^\fB]\fR
1393 \fBdelete \fIarray\^\fR
1394 \fBexit\fR [ \fIexpression\fR ]
1395 \fB{ \fIstatements \fB}
1396 .fi
1397 .RE
1398 .SS "I/O Statements"
1399 .PP
1400 The input/output statements are as follows:
1401 .PP
1402 .TP "\w'\fBprintf \fIfmt, expr-list\fR'u+1n"
1403 .BI close( file )
1404 Close file (or pipe, see below).
1405 .TP
1406 .B getline
1407 Set
1408 .B $0
1409 from next input record; set
1410 .BR NF ,
1411 .BR NR ,
1412 .BR FNR .
1413 .TP
1414 .BI "getline <" file
1415 Set
1416 .B $0
1417 from next record of
1418 .IR file ;
1419 set
1420 .BR NF .
1421 .TP
1422 .BI getline " var"
1423 Set
1424 .I var
1425 from next input record; set
1426 .BR NR ,
1427 .BR FNR .
1428 .TP
1429 .BI getline " var" " <" file
1430 Set
1431 .I var
1432 from next record of
1433 .IR file .
1434 .TP
1435 .B next
1436 Stop processing the current input record. The next input record
1437 is read and processing starts over with the first pattern in the
1438 AWK program. If the end of the input data is reached, the
1439 .B END
1440 block(s), if any, are executed.
1441 .TP
1442 .B "nextfile"
1443 Stop processing the current input file.  The next input record read
1444 comes from the next input file.
1445 .B FILENAME
1446 and
1447 .B ARGIND
1448 are updated,
1449 .B FNR
1450 is reset to 1, and processing starts over with the first pattern in the
1451 AWK program. If the end of the input data is reached, the
1452 .B END
1453 block(s), if any, are executed.
1454 .B NOTE:
1455 Earlier versions of gawk used
1456 .BR "next file" ,
1457 as two words. While this usage is still recognized, it generates a
1458 warning message and will eventually be removed.
1459 .TP
1460 .B print
1461 Prints the current record.
1462 The output record is terminated with the value of the
1463 .B ORS
1464 variable.
1465 .TP
1466 .BI print " expr-list"
1467 Prints expressions.
1468 Each expression is separated by the value of the
1469 .B OFS
1470 variable.
1471 The output record is terminated with the value of the
1472 .B ORS
1473 variable.
1474 .TP
1475 .BI print " expr-list" " >" file
1476 Prints expressions on
1477 .IR file .
1478 Each expression is separated by the value of the
1479 .B OFS
1480 variable. The output record is terminated with the value of the
1481 .B ORS
1482 variable.
1483 .TP
1484 .BI printf " fmt, expr-list"
1485 Format and print.
1486 .TP
1487 .BI printf " fmt, expr-list" " >" file
1488 Format and print on
1489 .IR file .
1490 .TP
1491 .BI system( cmd-line )
1492 Execute the command
1493 .IR cmd-line ,
1494 and return the exit status.
1495 (This may not be available on non-\*(PX systems.)
1496 .TP
1497 \&\fBfflush(\fR[\fIfile\^\fR]\fB)\fR
1498 Flush any buffers associated with the open output file or pipe
1499 .IR file .
1500 If
1501 .I file
1502 is missing, then standard output is flushed.
1503 If
1504 .I file
1505 is the null string,
1506 then all open output files and pipes
1507 have their buffers flushed.
1508 .PP
1509 Other input/output redirections are also allowed. For
1510 .B print
1511 and
1512 .BR printf ,
1513 .BI >> file
1514 appends output to the
1515 .IR file ,
1516 while
1517 .BI | " command"
1518 writes on a pipe.
1519 In a similar fashion,
1520 .IB command " | getline"
1521 pipes into
1522 .BR getline .
1523 The
1524 .BR getline
1525 command will return 0 on end of file, and \-1 on an error.
1526 .SS The \fIprintf\fP\^ Statement
1527 .PP
1528 The AWK versions of the
1529 .B printf
1530 statement and
1531 .B sprintf()
1532 function
1533 (see below)
1534 accept the following conversion specification formats:
1535 .TP
1536 .B %c
1537 An \s-1ASCII\s+1 character.
1538 If the argument used for
1539 .B %c
1540 is numeric, it is treated as a character and printed.
1541 Otherwise, the argument is assumed to be a string, and the only first
1542 character of that string is printed.
1543 .TP
1544 .PD 0
1545 .B %d
1546 .TP
1547 .PD
1548 .B %i
1549 A decimal number (the integer part).
1550 .TP
1551 .PD 0
1552 .B %e
1553 .TP
1554 .PD
1555 .B %E
1556 A floating point number of the form
1557 .BR [\-]d.dddddde[+\^\-]dd .
1558 The
1559 .B %E
1560 format uses
1561 .B E
1562 instead of
1563 .BR e .
1564 .TP
1565 .B %f
1566 A floating point number of the form
1567 .BR [\-]ddd.dddddd .
1568 .TP
1569 .PD 0
1570 .B %g
1571 .TP
1572 .PD
1573 .B %G
1574 Use
1575 .B %e
1576 or
1577 .B %f
1578 conversion, whichever is shorter, with nonsignificant zeros suppressed.
1579 The
1580 .B %G
1581 format uses
1582 .B %E
1583 instead of
1584 .BR %e .
1585 .TP
1586 .B %o
1587 An unsigned octal number (again, an integer).
1588 .TP
1589 .B %s
1590 A character string.
1591 .TP
1592 .PD 0
1593 .B %x
1594 .TP
1595 .PD
1596 .B %X
1597 An unsigned hexadecimal number (an integer).
1598 .The
1599 .B %X
1600 format uses
1601 .B ABCDEF
1602 instead of
1603 .BR abcdef .
1604 .TP
1605 .B %%
1606 A single
1607 .B %
1608 character; no argument is converted.
1609 .PP
1610 There are optional, additional parameters that may lie between the
1611 .B %
1612 and the control letter:
1613 .TP
1614 .B \-
1615 The expression should be left-justified within its field.
1616 .TP
1617 .I space
1618 For numeric conversions, prefix positive values with a space, and
1619 negative values with a minus sign.
1620 .TP
1621 .B +
1622 The plus sign, used before the width modifier (see below),
1623 says to always supply a sign for numeric conversions, even if the data
1624 to be formatted is positive. The
1625 .B +
1626 overrides the space modifier.
1627 .TP
1628 .B #
1629 Use an ``alternate form'' for certain control letters.
1630 For
1631 .BR %o ,
1632 supply a leading zero.
1633 For
1634 .BR %x ,
1635 and
1636 .BR %X ,
1637 supply a leading
1638 .BR 0x 
1639 or
1640 .BR 0X 
1641 for
1642 a nonzero result.
1643 For
1644 .BR %e ,
1645 .BR %E ,
1646 and
1647 .BR %f ,
1648 the result will always contain a
1649 decimal point.
1650 For
1651 .BR %g ,
1652 and
1653 .BR %G ,
1654 trailing zeros are not removed from the result.
1655 .TP
1656 .B 0
1657 A leading
1658 .B 0
1659 (zero) acts as a flag, that indicates output should be
1660 padded with zeroes instead of spaces.
1661 This applies even to non-numeric output formats.
1662 This flag only has an effect when the field width is wider than the
1663 value to be printed.
1664 .TP
1665 .I width
1666 The field should be padded to this width. The field is normally padded
1667 with spaces.  If the
1668 .B 0
1669 flag has been used, it is padded with zeroes.
1670 .TP
1671 .BI \&. prec
1672 A number that specifies the precision to use when printing.
1673 For the
1674 .BR %e ,
1675 .BR %E ,
1676 and
1677 .BR %f 
1678 formats, this specifies the
1679 number of digits you want printed to the right of the decimal point.
1680 For the
1681 .BR %g ,
1682 and
1683 .B %G
1684 formats, it specifies the maximum number
1685 of significant digits.  For the
1686 .BR %d ,
1687 .BR %o ,
1688 .BR %i ,
1689 .BR %u ,
1690 .BR %x ,
1691 and
1692 .B %X
1693 formats, it specifies the minimum number of
1694 digits to print.  For a string, it specifies the maximum number of
1695 characters from the string that should be printed.
1696 .PP
1697 The dynamic
1698 .I width
1699 and
1700 .I prec
1701 capabilities of the \*(AN C
1702 .B printf()
1703 routines are supported.
1704 A
1705 .B *
1706 in place of either the
1707 .B width
1708 or
1709 .B prec
1710 specifications will cause their values to be taken from
1711 the argument list to
1712 .B printf
1713 or
1714 .BR sprintf() .
1715 .SS Special File Names
1716 .PP
1717 When doing I/O redirection from either
1718 .B print
1719 or
1720 .B printf
1721 into a file,
1722 or via
1723 .B getline
1724 from a file,
1725 .I gawk
1726 recognizes certain special filenames internally.  These filenames
1727 allow access to open file descriptors inherited from
1728 .IR gawk 's
1729 parent process (usually the shell).
1730 Other special filenames provide access to information about the running
1731 .B gawk
1732 process.
1733 The filenames are:
1734 .TP \w'\fB/dev/stdout\fR'u+1n
1735 .B /dev/pid
1736 Reading this file returns the process ID of the current process,
1737 in decimal, terminated with a newline.
1738 .TP
1739 .B /dev/ppid
1740 Reading this file returns the parent process ID of the current process,
1741 in decimal, terminated with a newline.
1742 .TP
1743 .B /dev/pgrpid
1744 Reading this file returns the process group ID of the current process,
1745 in decimal, terminated with a newline.
1746 .TP
1747 .B /dev/user
1748 Reading this file returns a single record terminated with a newline.
1749 The fields are separated with spaces.
1750 .B $1
1751 is the value of the
1752 .IR getuid (2)
1753 system call,
1754 .B $2
1755 is the value of the
1756 .IR geteuid (2)
1757 system call,
1758 .B $3
1759 is the value of the
1760 .IR getgid (2)
1761 system call, and
1762 .B $4
1763 is the value of the
1764 .IR getegid (2)
1765 system call.
1766 If there are any additional fields, they are the group IDs returned by
1767 .IR getgroups (2).
1768 Multiple groups may not be supported on all systems.
1769 .TP
1770 .B /dev/stdin
1771 The standard input.
1772 .TP
1773 .B /dev/stdout
1774 The standard output.
1775 .TP
1776 .B /dev/stderr
1777 The standard error output.
1778 .TP
1779 .BI /dev/fd/\^ n
1780 The file associated with the open file descriptor
1781 .IR n .
1782 .PP
1783 These are particularly useful for error messages. For example:
1784 .PP
1785 .RS
1786 .ft B
1787 print "You blew it!" > "/dev/stderr"
1788 .ft R
1789 .RE
1790 .PP
1791 whereas you would otherwise have to use
1792 .PP
1793 .RS
1794 .ft B
1795 print "You blew it!" | "cat 1>&2"
1796 .ft R
1797 .RE
1798 .PP
1799 These file names may also be used on the command line to name data files.
1800 .SS Numeric Functions
1801 .PP
1802 AWK has the following pre-defined arithmetic functions:
1803 .PP
1804 .TP \w'\fBsrand(\fR[\fIexpr\^\fR]\fB)\fR'u+1n
1805 .BI atan2( y , " x" )
1806 returns the arctangent of
1807 .I y/x
1808 in radians.
1809 .TP
1810 .BI cos( expr )
1811 returns the cosine of
1812 .IR expr ,
1813 which is in radians.
1814 .TP
1815 .BI exp( expr )
1816 the exponential function.
1817 .TP
1818 .BI int( expr )
1819 truncates to integer.
1820 .TP
1821 .BI log( expr )
1822 the natural logarithm function.
1823 .TP
1824 .B rand()
1825 returns a random number between 0 and 1.
1826 .TP
1827 .BI sin( expr )
1828 returns the sine of
1829 .IR expr ,
1830 which is in radians.
1831 .TP
1832 .BI sqrt( expr )
1833 the square root function.
1834 .TP
1835 \&\fBsrand(\fR[\fIexpr\^\fR]\fB)\fR
1836 uses
1837 .I expr
1838 as a new seed for the random number generator. If no
1839 .I expr
1840 is provided, the time of day will be used.
1841 The return value is the previous seed for the random
1842 number generator.
1843 .SS String Functions
1844 .PP
1845 .I Gawk
1846 has the following pre-defined string functions:
1847 .PP
1848 .TP "\w'\fBsprintf(\^\fIfmt\fB\^, \fIexpr-list\^\fB)\fR'u+1n"
1849 \fBgensub(\fIr\fB, \fIs\fB, \fIh \fR[\fB, \fIt\fR]\fB)\fR
1850 search the target string
1851 .I t
1852 for matches of the regular expression
1853 .IR r .
1854 If
1855 .I h
1856 is a string beginning with
1857 .B g
1858 or
1859 .BR G ,
1860 then replace all matches of
1861 .I r
1862 with
1863 .IR s .
1864 Otherwise,
1865 .I h
1866 is a number indicating which match of
1867 .I r
1868 to replace.
1869 If no
1870 .I t
1871 is supplied,
1872 .B $0
1873 is used instead.
1874 Within the replacement text
1875 .IR s ,
1876 the sequence
1877 .BI \e n\fR,
1878 where
1879 .I n
1880 is a digit from 1 to 9, may be used to indicate just the text that
1881 matched the
1882 .IR n 'th
1883 parenthesized subexpression. The sequence
1884 .B \e0
1885 represents the entire matched text, as does the character
1886 .BR & .
1887 Unlike
1888 .B sub()
1889 and
1890 .BR gsub() ,
1891 the modified string is returned as the result of the function,
1892 and the original target string is
1893 .I not
1894 changed.
1895 .TP "\w'\fBsprintf(\^\fIfmt\fB\^, \fIexpr-list\^\fB)\fR'u+1n"
1896 \fBgsub(\fIr\fB, \fIs \fR[\fB, \fIt\fR]\fB)\fR
1897 for each substring matching the regular expression
1898 .I r
1899 in the string
1900 .IR t ,
1901 substitute the string
1902 .IR s ,
1903 and return the number of substitutions.
1904 If
1905 .I t
1906 is not supplied, use
1907 .BR $0 .
1908 An
1909 .B &
1910 in the replacement text is replaced with the text that was actually matched.
1911 Use
1912 .B \e&
1913 to get a literal
1914 .BR & .
1915 See
1916 .I "AWK Language Programming"
1917 for a fuller discussion of the rules for
1918 .BR &'s
1919 and backslashes in the replacement text of
1920 .BR sub() ,
1921 .BR gsub() ,
1922 and
1923 .BR gensub() .
1924 .TP
1925 .BI index( s , " t" )
1926 returns the index of the string
1927 .I t
1928 in the string
1929 .IR s ,
1930 or 0 if
1931 .I t
1932 is not present.
1933 .TP
1934 \fBlength(\fR[\fIs\fR]\fB)
1935 returns the length of the string
1936 .IR s ,
1937 or the length of
1938 .B $0
1939 if
1940 .I s
1941 is not supplied.
1942 .TP
1943 .BI match( s , " r" )
1944 returns the position in
1945 .I s
1946 where the regular expression
1947 .I r
1948 occurs, or 0 if
1949 .I r
1950 is not present, and sets the values of
1951 .B RSTART
1952 and
1953 .BR RLENGTH .
1954 .TP
1955 \fBsplit(\fIs\fB, \fIa \fR[\fB, \fIr\fR]\fB)\fR
1956 splits the string
1957 .I s
1958 into the array
1959 .I a
1960 on the regular expression
1961 .IR r ,
1962 and returns the number of fields. If
1963 .I r
1964 is omitted,
1965 .B FS
1966 is used instead.
1967 The array
1968 .I a
1969 is cleared first.
1970 Splitting behaves identically to field splitting, described above.
1971 .TP
1972 .BI sprintf( fmt , " expr-list" )
1973 prints
1974 .I expr-list
1975 according to
1976 .IR fmt ,
1977 and returns the resulting string.
1978 .TP
1979 \fBsub(\fIr\fB, \fIs \fR[\fB, \fIt\fR]\fB)\fR
1980 just like
1981 .BR gsub() ,
1982 but only the first matching substring is replaced.
1983 .TP
1984 \fBsubstr(\fIs\fB, \fIi \fR[\fB, \fIn\fR]\fB)\fR
1985 returns the at most
1986 .IR n -character
1987 substring of
1988 .I s
1989 starting at
1990 .IR i .
1991 If
1992 .I n
1993 is omitted, the rest of
1994 .I s
1995 is used.
1996 .TP
1997 .BI tolower( str )
1998 returns a copy of the string
1999 .IR str ,
2000 with all the upper-case characters in
2001 .I str
2002 translated to their corresponding lower-case counterparts.
2003 Non-alphabetic characters are left unchanged.
2004 .TP
2005 .BI toupper( str )
2006 returns a copy of the string
2007 .IR str ,
2008 with all the lower-case characters in
2009 .I str
2010 translated to their corresponding upper-case counterparts.
2011 Non-alphabetic characters are left unchanged.
2012 .SS Time Functions
2013 .PP
2014 Since one of the primary uses of AWK programs is processing log files
2015 that contain time stamp information,
2016 .I gawk
2017 provides the following two functions for obtaining time stamps and
2018 formatting them.
2019 .PP
2020 .TP "\w'\fBsystime()\fR'u+1n"
2021 .B systime()
2022 returns the current time of day as the number of seconds since the Epoch
2023 (Midnight UTC, January 1, 1970 on \*(PX systems).
2024 .TP
2025 \fBstrftime(\fR[\fIformat \fR[\fB, \fItimestamp\fR]]\fB)\fR
2026 formats
2027 .I timestamp
2028 according to the specification in
2029 .IR format.
2030 The
2031 .I timestamp
2032 should be of the same form as returned by
2033 .BR systime() .
2034 If
2035 .I timestamp
2036 is missing, the current time of day is used.
2037 If
2038 .I format
2039 is missing, a default format equivalent to the output of
2040 .IR date (1)
2041 will be used.
2042 See the specification for the
2043 .B strftime()
2044 function in \*(AN C for the format conversions that are
2045 guaranteed to be available.
2046 A public-domain version of
2047 .IR strftime (3)
2048 and a man page for it come with
2049 .IR gawk ;
2050 if that version was used to build
2051 .IR gawk ,
2052 then all of the conversions described in that man page are available to
2053 .IR gawk.
2054 .SS String Constants
2055 .PP
2056 String constants in AWK are sequences of characters enclosed
2057 between double quotes (\fB"\fR). Within strings, certain
2058 .I "escape sequences"
2059 are recognized, as in C. These are:
2060 .PP
2061 .TP \w'\fB\e\^\fIddd\fR'u+1n
2062 .B \e\e
2063 A literal backslash.
2064 .TP
2065 .B \ea
2066 The ``alert'' character; usually the \s-1ASCII\s+1 \s-1BEL\s+1 character.
2067 .TP
2068 .B \eb
2069 backspace.
2070 .TP
2071 .B \ef
2072 form-feed.
2073 .TP
2074 .B \en
2075 newline.
2076 .TP
2077 .B \er
2078 carriage return.
2079 .TP
2080 .B \et
2081 horizontal tab.
2082 .TP
2083 .B \ev
2084 vertical tab.
2085 .TP
2086 .BI \ex "\^hex digits"
2087 The character represented by the string of hexadecimal digits following
2088 the
2089 .BR \ex .
2090 As in \*(AN C, all following hexadecimal digits are considered part of
2091 the escape sequence.
2092 (This feature should tell us something about language design by committee.)
2093 E.g., \fB"\ex1B"\fR is the \s-1ASCII\s+1 \s-1ESC\s+1 (escape) character.
2094 .TP
2095 .BI \e ddd
2096 The character represented by the 1-, 2-, or 3-digit sequence of octal
2097 digits. E.g. \fB"\e033"\fR is the \s-1ASCII\s+1 \s-1ESC\s+1 (escape) character.
2098 .TP
2099 .BI \e c
2100 The literal character
2101 .IR c\^ .
2102 .PP
2103 The escape sequences may also be used inside constant regular expressions
2104 (e.g.,
2105 .B "/[\ \et\ef\en\er\ev]/"
2106 matches whitespace characters).
2107 .PP
2108 In compatibility mode, the characters represented by octal and
2109 hexadecimal escape sequences are treated literally when used in
2110 regexp constants. Thus,
2111 .B /a\e52b/
2112 is equivalent to
2113 .BR /a\e*b/ .
2114 .SH FUNCTIONS
2115 Functions in AWK are defined as follows:
2116 .PP
2117 .RS
2118 \fBfunction \fIname\fB(\fIparameter list\fB) { \fIstatements \fB}\fR
2119 .RE
2120 .PP
2121 Functions are executed when they are called from within expressions
2122 in either patterns or actions.  Actual parameters supplied in the function
2123 call are used to instantiate the formal parameters declared in the function.
2124 Arrays are passed by reference, other variables are passed by value.
2125 .PP
2126 Since functions were not originally part of the AWK language, the provision
2127 for local variables is rather clumsy: They are declared as extra parameters
2128 in the parameter list. The convention is to separate local variables from
2129 real parameters by extra spaces in the parameter list. For example:
2130 .PP
2131 .RS
2132 .ft B
2133 .nf
2134 function  f(p, q,     a, b)     # a & b are local
2135 {
2136         \&.....
2137 }
2138
2139 /abc/   { ... ; f(1, 2) ; ... }
2140 .fi
2141 .ft R
2142 .RE
2143 .PP
2144 The left parenthesis in a function call is required
2145 to immediately follow the function name,
2146 without any intervening white space.
2147 This is to avoid a syntactic ambiguity with the concatenation operator.
2148 This restriction does not apply to the built-in functions listed above.
2149 .PP
2150 Functions may call each other and may be recursive.
2151 Function parameters used as local variables are initialized
2152 to the null string and the number zero upon function invocation.
2153 .PP
2154 Use
2155 .BI return " expr"
2156 to return a value from a function. The return value is undefined if no
2157 value is provided, or if the function returns by ``falling off'' the
2158 end.
2159 .PP
2160 If
2161 .B \-\^\-lint
2162 has been provided,
2163 .I gawk
2164 will warn about calls to undefined functions at parse time,
2165 instead of at run time.
2166 Calling an undefined function at run time is a fatal error.
2167 .PP
2168 The word
2169 .B func
2170 may be used in place of
2171 .BR function .
2172 .SH EXAMPLES
2173 .nf
2174 Print and sort the login names of all users:
2175
2176 .ft B
2177         BEGIN   { FS = ":" }
2178                 { print $1 | "sort" }
2179
2180 .ft R
2181 Count lines in a file:
2182
2183 .ft B
2184                 { nlines++ }
2185         END     { print nlines }
2186
2187 .ft R
2188 Precede each line by its number in the file:
2189
2190 .ft B
2191         { print FNR, $0 }
2192
2193 .ft R
2194 Concatenate and line number (a variation on a theme):
2195
2196 .ft B
2197         { print NR, $0 }
2198 .ft R
2199 .fi
2200 .SH SEE ALSO
2201 .IR egrep (1),
2202 .IR getpid (2),
2203 .IR getppid (2),
2204 .IR getpgrp (2),
2205 .IR getuid (2),
2206 .IR geteuid (2),
2207 .IR getgid (2),
2208 .IR getegid (2),
2209 .IR getgroups (2)
2210 .PP
2211 .IR "The AWK Programming Language" ,
2212 Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger,
2213 Addison-Wesley, 1988. ISBN 0-201-07981-X.
2214 .PP
2215 .IR "AWK Language Programming" ,
2216 Edition 1.0, published by the Free Software Foundation, 1995.
2217 .SH POSIX COMPATIBILITY
2218 A primary goal for
2219 .I gawk
2220 is compatibility with the \*(PX standard, as well as with the
2221 latest version of \*(UX
2222 .IR awk .
2223 To this end,
2224 .I gawk
2225 incorporates the following user visible
2226 features which are not described in the AWK book,
2227 but are part of the Bell Labs version of
2228 .IR awk ,
2229 and are in the \*(PX standard.
2230 .PP
2231 The
2232 .B \-v
2233 option for assigning variables before program execution starts is new.
2234 The book indicates that command line variable assignment happens when
2235 .I awk
2236 would otherwise open the argument as a file, which is after the
2237 .B BEGIN
2238 block is executed.  However, in earlier implementations, when such an
2239 assignment appeared before any file names, the assignment would happen
2240 .I before
2241 the
2242 .B BEGIN
2243 block was run.  Applications came to depend on this ``feature.''
2244 When
2245 .I awk
2246 was changed to match its documentation, this option was added to
2247 accommodate applications that depended upon the old behavior.
2248 (This feature was agreed upon by both the AT&T and GNU developers.)
2249 .PP
2250 The
2251 .B \-W
2252 option for implementation specific features is from the \*(PX standard.
2253 .PP
2254 When processing arguments,
2255 .I gawk
2256 uses the special option ``\fB\-\^\-\fP'' to signal the end of
2257 arguments.
2258 In compatibility mode, it will warn about, but otherwise ignore,
2259 undefined options.
2260 In normal operation, such arguments are passed on to the AWK program for
2261 it to process.
2262 .PP
2263 The AWK book does not define the return value of
2264 .BR srand() .
2265 The \*(PX standard
2266 has it return the seed it was using, to allow keeping track
2267 of random number sequences. Therefore
2268 .B srand()
2269 in
2270 .I gawk
2271 also returns its current seed.
2272 .PP
2273 Other new features are:
2274 The use of multiple
2275 .B \-f
2276 options (from MKS
2277 .IR awk );
2278 the
2279 .B ENVIRON
2280 array; the
2281 .BR \ea ,
2282 and
2283 .BR \ev
2284 escape sequences (done originally in
2285 .I gawk
2286 and fed back into AT&T's); the
2287 .B tolower()
2288 and
2289 .B toupper()
2290 built-in functions (from AT&T); and the \*(AN C conversion specifications in
2291 .B printf
2292 (done first in AT&T's version).
2293 .SH GNU EXTENSIONS
2294 .I Gawk
2295 has a number of extensions to \*(PX
2296 .IR awk .
2297 They are described in this section.  All the extensions described here
2298 can be disabled by
2299 invoking
2300 .I gawk
2301 with the
2302 .B \-\^\-traditional
2303 option.
2304 .PP
2305 The following features of
2306 .I gawk
2307 are not available in
2308 \*(PX
2309 .IR awk .
2310 .RS
2311 .TP \w'\(bu'u+1n
2312 \(bu
2313 The
2314 .B \ex
2315 escape sequence.
2316 (Disabled with
2317 .BR \-\^\-posix .)
2318 .TP \w'\(bu'u+1n
2319 \(bu
2320 The
2321 .B fflush()
2322 function.
2323 (Disabled with
2324 .BR \-\^\-posix .)
2325 .TP
2326 \(bu
2327 The
2328 .BR systime(),
2329 .BR strftime(),
2330 and
2331 .B gensub()
2332 functions.
2333 .TP
2334 \(bu
2335 The special file names available for I/O redirection are not recognized.
2336 .TP
2337 \(bu
2338 The
2339 .BR ARGIND ,
2340 .BR ERRNO ,
2341 and
2342 .B RT
2343 variables are not special.
2344 .TP
2345 \(bu
2346 The
2347 .B IGNORECASE
2348 variable and its side-effects are not available.
2349 .TP
2350 \(bu
2351 The
2352 .B FIELDWIDTHS
2353 variable and fixed-width field splitting.
2354 .TP
2355 \(bu
2356 The use of
2357 .B RS
2358 as a regular expression.
2359 .TP
2360 \(bu
2361 The ability to split out individual characters using the null string
2362 as the value of
2363 .BR FS ,
2364 and as the third argument to
2365 .BR split() .
2366 .TP
2367 \(bu
2368 No path search is performed for files named via the
2369 .B \-f
2370 option.  Therefore the
2371 .B AWKPATH
2372 environment variable is not special.
2373 .TP
2374 \(bu
2375 The use of
2376 .B "nextfile"
2377 to abandon processing of the current input file.
2378 .TP
2379 \(bu
2380 The use of
2381 .BI delete " array"
2382 to delete the entire contents of an array.
2383 .RE
2384 .PP
2385 The AWK book does not define the return value of the
2386 .B close()
2387 function.
2388 .IR Gawk\^ 's
2389 .B close()
2390 returns the value from
2391 .IR fclose (3),
2392 or
2393 .IR pclose (3),
2394 when closing a file or pipe, respectively.
2395 .PP
2396 When
2397 .I gawk
2398 is invoked with the
2399 .B \-\^\-traditional
2400 option,
2401 if the
2402 .I fs
2403 argument to the
2404 .B \-F
2405 option is ``t'', then
2406 .B FS
2407 will be set to the tab character.
2408 Note that typing
2409 .B "gawk \-F\et \&..."
2410 simply causes the shell to quote the ``t,'', and does not pass
2411 ``\et'' to the
2412 .B \-F
2413 option.
2414 Since this is a rather ugly special case, it is not the default behavior.
2415 This behavior also does not occur if
2416 .B \-\^\-posix
2417 has been specified.
2418 To really get a tab character as the field separator, it is best to use
2419 quotes:
2420 .BR "gawk \-F'\et' \&..." .
2421 .ig
2422 .PP
2423 If
2424 .I gawk
2425 was compiled for debugging, it will
2426 accept the following additional options:
2427 .TP
2428 .PD 0
2429 .B \-Wparsedebug
2430 .TP
2431 .PD
2432 .B \-\^\-parsedebug
2433 Turn on
2434 .IR yacc (1)
2435 or
2436 .IR bison (1)
2437 debugging output during program parsing.
2438 This option should only be of interest to the
2439 .I gawk
2440 maintainers, and may not even be compiled into
2441 .IR gawk .
2442 ..
2443 .SH HISTORICAL FEATURES
2444 There are two features of historical AWK implementations that
2445 .I gawk
2446 supports.
2447 First, it is possible to call the
2448 .B length()
2449 built-in function not only with no argument, but even without parentheses!
2450 Thus,
2451 .RS
2452 .PP
2453 .ft B
2454 a = length      # Holy Algol 60, Batman!
2455 .ft R
2456 .RE
2457 .PP
2458 is the same as either of
2459 .RS
2460 .PP
2461 .ft B
2462 a = length()
2463 .br
2464 a = length($0)
2465 .ft R
2466 .RE
2467 .PP
2468 This feature is marked as ``deprecated'' in the \*(PX standard, and
2469 .I gawk
2470 will issue a warning about its use if
2471 .B \-\^\-lint
2472 is specified on the command line.
2473 .PP
2474 The other feature is the use of either the
2475 .B continue
2476 or the
2477 .B break
2478 statements outside the body of a
2479 .BR while ,
2480 .BR for ,
2481 or
2482 .B do
2483 loop.  Traditional AWK implementations have treated such usage as
2484 equivalent to the
2485 .B next
2486 statement.
2487 .I Gawk
2488 will support this usage if
2489 .B \-\^\-traditional
2490 has been specified.
2491 .SH ENVIRONMENT
2492 If
2493 .B POSIXLY_CORRECT
2494 exists in the environment, then
2495 .I gawk
2496 behaves exactly as if
2497 .B \-\^\-posix
2498 had been specified on the command line.
2499 If
2500 .B \-\^\-lint
2501 has been specified,
2502 .I gawk
2503 will issue a warning message to this effect.
2504 .PP
2505 The
2506 .B AWKPATH
2507 environment variable can be used to provide a list of directories that
2508 .I gawk
2509 will search when looking for files named via the
2510 .B \-f
2511 and
2512 .B \-\^\-file
2513 options.
2514 .SH BUGS
2515 The
2516 .B \-F
2517 option is not necessary given the command line variable assignment feature;
2518 it remains only for backwards compatibility.
2519 .PP
2520 If your system actually has support for
2521 .B /dev/fd
2522 and the associated
2523 .BR /dev/stdin ,
2524 .BR /dev/stdout ,
2525 and
2526 .B /dev/stderr
2527 files, you may get different output from
2528 .I gawk
2529 than you would get on a system without those files.  When
2530 .I gawk
2531 interprets these files internally, it synchronizes output to the standard
2532 output with output to
2533 .BR /dev/stdout ,
2534 while on a system with those files, the output is actually to different
2535 open files.
2536 Caveat Emptor.
2537 .PP
2538 Syntactically invalid single character programs tend to overflow
2539 the parse stack, generating a rather unhelpful message.  Such programs
2540 are surprisingly difficult to diagnose in the completely general case,
2541 and the effort to do so really is not worth it.
2542 .SH VERSION INFORMATION
2543 This man page documents
2544 .IR gawk ,
2545 version 3.0.4.
2546 .SH AUTHORS
2547 The original version of \*(UX
2548 .I awk
2549 was designed and implemented by Alfred Aho,
2550 Peter Weinberger, and Brian Kernighan of AT&T Bell Labs. Brian Kernighan
2551 continues to maintain and enhance it.
2552 .PP
2553 Paul Rubin and Jay Fenlason,
2554 of the Free Software Foundation, wrote
2555 .IR gawk ,
2556 to be compatible with the original version of
2557 .I awk
2558 distributed in Seventh Edition \*(UX.
2559 John Woods contributed a number of bug fixes.
2560 David Trueman, with contributions
2561 from Arnold Robbins, made
2562 .I gawk
2563 compatible with the new version of \*(UX
2564 .IR awk .
2565 Arnold Robbins is the current maintainer.
2566 .PP
2567 The initial DOS port was done by Conrad Kwok and Scott Garfinkle.
2568 Scott Deifik is the current DOS maintainer.  Pat Rankin did the
2569 port to VMS, and Michal Jaegermann did the port to the Atari ST.
2570 The port to OS/2 was done by Kai Uwe Rommel, with contributions and
2571 help from Darrel Hankerson.  Fred Fish supplied support for the Amiga.
2572 .SH BUG REPORTS
2573 If you find a bug in
2574 .IR gawk ,
2575 please send electronic mail to
2576 .BR bug-gnu-utils@gnu.org ,
2577 .I with
2578 a carbon copy to
2579 .BR arnold@gnu.org .
2580 Please include your operating system and its revision, the version of
2581 .IR gawk ,
2582 what C compiler you used to compile it, and a test program
2583 and data that are as small as possible for reproducing the problem.
2584 .PP
2585 Before sending a bug report, please do two things. First, verify that
2586 you have the latest version of
2587 .IR gawk .
2588 Many bugs (usually subtle ones) are fixed at each release, and if
2589 yours is out of date, the problem may already have been solved.
2590 Second, please read this man page and the reference manual carefully to
2591 be sure that what you think is a bug really is, instead of just a quirk
2592 in the language.
2593 .PP
2594 Whatever you do, do
2595 .B NOT
2596 post a bug report in
2597 .BR comp.lang.awk .
2598 While the
2599 .I gawk
2600 developers occasionally read this newsgroup, posting bug reports there
2601 is an unreliable way to report bugs. Instead, please use the electronic mail
2602 addresses given above.
2603 .SH ACKNOWLEDGEMENTS
2604 Brian Kernighan of Bell Labs
2605 provided valuable assistance during testing and debugging.
2606 We thank him.
2607 .SH COPYING PERMISSIONS
2608 Copyright \(co) 1996,97,98,99 Free Software Foundation, Inc.
2609 .PP
2610 Permission is granted to make and distribute verbatim copies of
2611 this manual page provided the copyright notice and this permission
2612 notice are preserved on all copies.
2613 .ig
2614 Permission is granted to process this file through troff and print the
2615 results, provided the printed document carries copying permission
2616 notice identical to this one except for the removal of this paragraph
2617 (this paragraph not being relevant to the printed manual page).
2618 ..
2619 .PP
2620 Permission is granted to copy and distribute modified versions of this
2621 manual page under the conditions for verbatim copying, provided that
2622 the entire resulting derived work is distributed under the terms of a
2623 permission notice identical to this one.
2624 .PP
2625 Permission is granted to copy and distribute translations of this
2626 manual page into another language, under the above conditions for
2627 modified versions, except that this permission notice may be stated in
2628 a translation approved by the Foundation.