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