1GAWK(1)                        Utility Commands                        GAWK(1)
2
3
4

NAME

6       gawk - pattern scanning and processing language
7

SYNOPSIS

9       gawk [ POSIX or GNU style options ] -f program-file [ -- ] file ...
10       gawk [ POSIX or GNU style options ] [ -- ] program-text file ...
11

DESCRIPTION

13       Gawk  is  the  GNU Project's implementation of the AWK programming lan‐
14       guage.  It conforms to the definition of  the  language  in  the  POSIX
15       1003.1  standard.   This version in turn is based on the description in
16       The AWK Programming Language, by Aho, Kernighan, and Weinberger.   Gawk
17       provides  the additional features found in the current version of Brian
18       Kernighan's awk and numerous GNU-specific extensions.
19
20       The command line consists of options to gawk itself,  the  AWK  program
21       text  (if not supplied via the -f or -i options), and values to be made
22       available in the ARGC and ARGV pre-defined AWK variables.
23
24       When gawk is invoked with the --profile  option,  it  starts  gathering
25       profiling statistics from the execution of the program.  Gawk runs more
26       slowly in this mode, and automatically produces an execution profile in
27       the file awkprof.out when done.  See the --profile option, below.
28
29       Gawk  also has an integrated debugger. An interactive debugging session
30       can be started by supplying the --debug option to the command line.  In
31       this mode of execution, gawk loads the AWK source code and then prompts
32       for debugging commands.  Gawk can only debug AWK  program  source  pro‐
33       vided  with  the -f option.  The debugger is documented in GAWK: Effec‐
34       tive AWK Programming.
35

OPTION FORMAT

37       Gawk options may be either traditional POSIX-style one letter  options,
38       or  GNU-style  long  options.   POSIX  options start with a single “-”,
39       while long options start with “--”.  Long options are provided for both
40       GNU-specific features and for POSIX-mandated features.
41
42       Gawk-specific  options  are  typically used in long-option form.  Argu‐
43       ments to long options are either joined with the option by an  =  sign,
44       with no intervening spaces, or they may be provided in the next command
45       line argument.  Long options may be abbreviated, as long as the  abbre‐
46       viation remains unique.
47
48       Additionally,  every  long  option has a corresponding short option, so
49       that the option's functionality may be used from within #!   executable
50       scripts.
51

OPTIONS

53       Gawk accepts the following options.  Standard options are listed first,
54       followed by options for gawk extensions, listed alphabetically by short
55       option.
56
57       -f program-file
58       --file program-file
59              Read  the AWK program source from the file program-file, instead
60              of from the  first  command  line  argument.   Multiple  -f  (or
61              --file) options may be used.
62
63       -F fs
64       --field-separator fs
65              Use fs for the input field separator (the value of the FS prede‐
66              fined variable).
67
68       -v var=val
69       --assign var=val
70              Assign the value val to the variable var,  before  execution  of
71              the  program  begins.  Such variable values are available to the
72              BEGIN rule of an AWK program.
73
74       -b
75       --characters-as-bytes
76              Treat all input data as single-byte characters. In other  words,
77              don't  pay any attention to the locale information when attempt‐
78              ing to process strings as  multibyte  characters.   The  --posix
79              option overrides this one.
80
81       -c
82       --traditional
83              Run  in compatibility mode.  In compatibility mode, gawk behaves
84              identically to Brian Kernighan's awk; none of  the  GNU-specific
85              extensions  are recognized.  See GNU EXTENSIONS, below, for more
86              information.
87
88       -C
89       --copyright
90              Print the short version of the GNU copyright information message
91              on the standard output and exit successfully.
92
93       -d[file]
94       --dump-variables[=file]
95              Print  a  sorted list of global variables, their types and final
96              values to file.  If no file is provided, gawk uses a file  named
97              awkvars.out in the current directory.
98              Having  a list of all the global variables is a good way to look
99              for typographical errors in your programs.  You would  also  use
100              this option if you have a large program with a lot of functions,
101              and you want to be sure that your functions don't  inadvertently
102              use  global  variables  that  you meant to be local.  (This is a
103              particularly easy mistake to make  with  simple  variable  names
104              like i, j, and so on.)
105
106       -D[file]
107       --debug[=file]
108              Enable  debugging  of  AWK  programs.   By default, the debugger
109              reads commands interactively from the keyboard (standard input).
110              The  optional file argument specifies a file with a list of com‐
111              mands for the debugger to execute non-interactively.
112
113       -e program-text
114       --source program-text
115              Use program-text as AWK program source code.  This option allows
116              the  easy  intermixing of library functions (used via the -f and
117              -i options) with source code entered on the command line.  It is
118              intended  primarily  for  medium  to  large AWK programs used in
119              shell scripts.
120
121       -E file
122       --exec file
123              Similar to -f, however, this is option  is  the  last  one  pro‐
124              cessed.   This should be used with #!  scripts, particularly for
125              CGI applications, to avoid passing in options or source code (!)
126              on  the  command line from a URL.  This option disables command-
127              line variable assignments.
128
129       -g
130       --gen-pot
131              Scan and parse the AWK program, and generate a GNU .pot  (Porta‐
132              ble Object Template) format file on standard output with entries
133              for all localizable strings in the program.  The program  itself
134              is  not  executed.   See  the  GNU gettext distribution for more
135              information on .pot files.
136
137       -h
138       --help Print a relatively short summary of the available options on the
139              standard  output.   (Per the GNU Coding Standards, these options
140              cause an immediate, successful exit.)
141
142       -i include-file
143       --include include-file
144              Load an awk source library.  This searches for the library using
145              the  AWKPATH environment variable.  If the initial search fails,
146              another attempt will be made after appending  the  .awk  suffix.
147              The  file  will be loaded only once (i.e., duplicates are elimi‐
148              nated), and the  code  does  not  constitute  the  main  program
149              source.
150
151       -l lib
152       --load lib
153              Load  a  gawk  extension  from  the  shared  library  lib.  This
154              searches for the library using the AWKLIBPATH environment  vari‐
155              able.  If the initial search fails, another attempt will be made
156              after appending the default shared library suffix for the  plat‐
157              form.   The  library  initialization  routine  is expected to be
158              named dl_load().
159
160       -L [value]
161       --lint[=value]
162              Provide warnings about constructs that are dubious or non-porta‐
163              ble  to other AWK implementations.  With an optional argument of
164              fatal, lint warnings become fatal errors.  This may be  drastic,
165              but  its use will certainly encourage the development of cleaner
166              AWK programs.  With an optional argument of invalid, only  warn‐
167              ings about things that are actually invalid are issued. (This is
168              not fully implemented yet.)
169
170       -M
171       --bignum
172              Force arbitrary precision arithmetic on numbers. This option has
173              no  effect  if  gawk  is not compiled to use the GNU MPFR and MP
174              libraries.  (In such a case, gawk issues a warning.)
175
176       -n
177       --non-decimal-data
178              Recognize octal and hexadecimal values in input data.  Use  this
179              option with great caution!
180
181       -N
182       --use-lc-numeric
183              Force  gawk  to  use  the  locale's decimal point character when
184              parsing input data.  Although the POSIX standard  requires  this
185              behavior,  and  gawk  does  so  when  --posix  is in effect, the
186              default is to follow traditional behavior and use  a  period  as
187              the  decimal  point, even in locales where the period is not the
188              decimal point character.   This  option  overrides  the  default
189              behavior,  without  the full draconian strictness of the --posix
190              option.
191
192       -o[file]
193       --pretty-print[=file]
194              Output a pretty printed version of the program to file.   If  no
195              file is provided, gawk uses a file named awkprof.out in the cur‐
196              rent directory.  Implies --no-optimize.
197
198       -O
199       --optimize
200              Enable gawk's default optimizations upon the internal  represen‐
201              tation  of  the  program.   Currently, this includes simple con‐
202              stant-folding, and tail call  elimination  for  recursive  func‐
203              tions.  This option is on by default.
204
205       -p[prof-file]
206       --profile[=prof-file]
207              Start  a profiling session, and send the profiling data to prof-
208              file.  The default is awkprof.out.  The profile contains  execu‐
209              tion  counts of each statement in the program in the left margin
210              and  function  call  counts  for  each  user-defined   function.
211              Implies --no-optimize.
212
213       -P
214       --posix
215              This  turns on compatibility mode, with the following additional
216              restrictions:
217
218              · \x escape sequences are not recognized.
219
220              · You cannot continue lines after ?  and :.
221
222              · The synonym func for the keyword function is not recognized.
223
224              · The operators ** and **= cannot be used in place of ^ and ^=.
225
226       -r
227       --re-interval
228              Enable the use of interval  expressions  in  regular  expression
229              matching (see Regular Expressions, below).  Interval expressions
230              were not traditionally available in the AWK language.  The POSIX
231              standard  added them, to make awk and egrep consistent with each
232              other.  They are enabled by default, but this option remains for
233              use with --traditional.
234
235       -s
236       --no-optimize
237              Disable gawk's default optimizations upon the internal represen‐
238              tation of the program.
239
240       -S
241       --sandbox
242              Run gawk in sandbox mode, disabling the system() function, input
243              redirection  with  getline,  output  redirection  with print and
244              printf,  and  loading  dynamic  extensions.   Command  execution
245              (through pipelines) is also disabled.  This effectively blocks a
246              script from accessing local  resources,  except  for  the  files
247              specified on the command line.
248
249       -t
250       --lint-old
251              Provide  warnings  about constructs that are not portable to the
252              original version of UNIX awk.
253
254       -V
255       --version
256              Print version information for this particular copy  of  gawk  on
257              the  standard  output.  This is useful mainly for knowing if the
258              current copy of gawk on your system is up to date  with  respect
259              to  whatever the Free Software Foundation is distributing.  This
260              is also useful when reporting bugs.  (Per the GNU  Coding  Stan‐
261              dards, these options cause an immediate, successful exit.)
262
263       --     Signal the end of options. This is useful to allow further argu‐
264              ments to the AWK program itself to start with a “-”.  This  pro‐
265              vides  consistency  with the argument parsing convention used by
266              most other POSIX programs.
267
268       In compatibility mode, any other options are flagged  as  invalid,  but
269       are  otherwise  ignored.   In normal operation, as long as program text
270       has been supplied, unknown options are passed on to the AWK program  in
271       the ARGV array for processing.  This is particularly useful for running
272       AWK programs via the #!  executable interpreter mechanism.
273
274       For POSIX compatibility, the -W option may be  used,  followed  by  the
275       name of a long option.
276

AWK PROGRAM EXECUTION

278       An  AWK program consists of a sequence of optional directives, pattern-
279       action statements, and optional function definitions.
280
281              @include "filename"
282              @load "filename"
283              pattern   { action statements }
284              function name(parameter list) { statements }
285
286       Gawk first reads the program source from the program-file(s) if  speci‐
287       fied, from arguments to --source, or from the first non-option argument
288       on the command line.  The -f and --source options may be used  multiple
289       times  on  the command line.  Gawk reads the program text as if all the
290       program-files and command  line  source  texts  had  been  concatenated
291       together.   This  is  useful  for  building libraries of AWK functions,
292       without having to include them in each new AWK program that uses  them.
293       It also provides the ability to mix library functions with command line
294       programs.
295
296       In addition, lines beginning with @include may be used to include other
297       source  files  into your program, making library use even easier.  This
298       is equivalent to using the -i option.
299
300       Lines beginning with @load may be used to load extension functions into
301       your program.  This is equivalent to using the -l option.
302
303       The  environment  variable  AWKPATH specifies a search path to use when
304       finding source files named with the -f and -i options.  If  this  vari‐
305       able  does  not  exist,  the  default path is ".:/usr/local/share/awk".
306       (The actual directory may vary, depending upon how gawk was  built  and
307       installed.)  If a file name given to the -f option contains a “/” char‐
308       acter, no path search is performed.
309
310       The environment variable AWKLIBPATH specifies a search path to use when
311       finding  source  files named with the -l option.  If this variable does
312       not exist, the default  path  is  "/usr/local/lib/gawk".   (The  actual
313       directory may vary, depending upon how gawk was built and installed.)
314
315       Gawk executes AWK programs in the following order.  First, all variable
316       assignments specified via the -v option are performed.  Next, gawk com‐
317       piles  the program into an internal form.  Then, gawk executes the code
318       in the BEGIN rule(s) (if any), and then  proceeds  to  read  each  file
319       named  in  the  ARGV array (up to ARGV[ARGC-1]).  If there are no files
320       named on the command line, gawk reads the standard input.
321
322       If a filename on the command line has the form var=val it is treated as
323       a  variable  assignment.   The  variable var will be assigned the value
324       val.  (This happens after any BEGIN rule(s) have  been  run.)   Command
325       line  variable assignment is most useful for dynamically assigning val‐
326       ues to the variables AWK uses to  control  how  input  is  broken  into
327       fields  and records.  It is also useful for controlling state if multi‐
328       ple passes are needed over a single data file.
329
330       If the value of a particular element of ARGV is empty (""), gawk  skips
331       over it.
332
333       For  each  input  file,  if  a BEGINFILE rule exists, gawk executes the
334       associated code before processing the contents of the file.  Similarly,
335       gawk  executes  the  code  associated with ENDFILE after processing the
336       file.
337
338       For each record in the input, gawk tests to see if it matches any  pat‐
339       tern  in  the  AWK  program.  For each pattern that the record matches,
340       gawk executes the associated action.  The patterns are  tested  in  the
341       order they occur in the program.
342
343       Finally,  after  all  the input is exhausted, gawk executes the code in
344       the END rule(s) (if any).
345
346   Command Line Directories
347       According to POSIX, files named on the awk command line  must  be  text
348       files.   The  behavior is ``undefined'' if they are not.  Most versions
349       of awk treat a directory on the command line as a fatal error.
350
351       Starting with version 4.0 of gawk, a directory on the command line pro‐
352       duces a warning, but is otherwise skipped.  If either of the --posix or
353       --traditional options is given, then gawk reverts to treating  directo‐
354       ries on the command line as a fatal error.
355

VARIABLES, RECORDS AND FIELDS

357       AWK variables are dynamic; they come into existence when they are first
358       used.  Their values are either floating-point numbers  or  strings,  or
359       both,  depending  upon  how  they  are used.  Additionally, gawk allows
360       variables to have regular-expression type.  AWK  also  has  one  dimen‐
361       sional  arrays; arrays with multiple dimensions may be simulated.  Gawk
362       provides true arrays of arrays; see Arrays, below.  Several pre-defined
363       variables  are set as a program runs; these are described as needed and
364       summarized below.
365
366   Records
367       Normally, records are separated by newline characters.  You can control
368       how  records are separated by assigning values to the built-in variable
369       RS.  If RS is any single character, that character  separates  records.
370       Otherwise,  RS is a regular expression.  Text in the input that matches
371       this regular expression separates the record.  However, in  compatibil‐
372       ity mode, only the first character of its string value is used for sep‐
373       arating records.  If RS is set to the null  string,  then  records  are
374       separated  by empty lines.  When RS is set to the null string, the new‐
375       line character always acts as a field separator, in addition  to  what‐
376       ever value FS may have.
377
378   Fields
379       As each input record is read, gawk splits the record into fields, using
380       the value of the FS variable as the field separator.  If FS is a single
381       character,  fields  are separated by that character.  If FS is the null
382       string, then each individual character becomes a separate field.   Oth‐
383       erwise, FS is expected to be a full regular expression.  In the special
384       case that FS is a single space, fields are separated by runs of  spaces
385       and/or tabs and/or newlines.  NOTE: The value of IGNORECASE (see below)
386       also affects how fields are split when FS is a regular expression,  and
387       how records are separated when RS is a regular expression.
388
389       If  the  FIELDWIDTHS  variable is set to a space-separated list of num‐
390       bers, each field is expected to have fixed width, and  gawk  splits  up
391       the record using the specified widths.  Each field width may optionally
392       be preceded by a colon-separated value specifying the number of charac‐
393       ters  to  skip  before  the  field starts.  The value of FS is ignored.
394       Assigning a new value to FS or FPAT overrides the use of FIELDWIDTHS.
395
396       Similarly, if the FPAT variable is set to a string representing a regu‐
397       lar expression, each field is made up of text that matches that regular
398       expression. In this case, the regular expression describes  the  fields
399       themselves, instead of the text that separates the fields.  Assigning a
400       new value to FS or FIELDWIDTHS overrides the use of FPAT.
401
402       Each field in the input record may be referenced by its  position:  $1,
403       $2,  and so on.  $0 is the whole record.  Fields need not be referenced
404       by constants:
405
406              n = 5
407              print $n
408
409       prints the fifth field in the input record.
410
411       The variable NF is set to the total  number  of  fields  in  the  input
412       record.
413
414       References  to non-existent fields (i.e., fields after $NF) produce the
415       null-string.  However, assigning to a non-existent field (e.g., $(NF+2)
416       = 5) increases the value of NF, creates any intervening fields with the
417       null string as their values, and causes the value of $0  to  be  recom‐
418       puted, with the fields being separated by the value of OFS.  References
419       to negative numbered fields  cause  a  fatal  error.   Decrementing  NF
420       causes  the  values  of  fields  past the new value to be lost, and the
421       value of $0 to be recomputed, with the fields being  separated  by  the
422       value of OFS.
423
424       Assigning  a  value  to an existing field causes the whole record to be
425       rebuilt when $0 is referenced.  Similarly,  assigning  a  value  to  $0
426       causes the record to be resplit, creating new values for the fields.
427
428   Built-in Variables
429       Gawk's built-in variables are:
430
431       ARGC        The  number  of  command  line  arguments (does not include
432                   options to gawk, or the program source).
433
434       ARGIND      The index in ARGV of the current file being processed.
435
436       ARGV        Array of command line arguments.  The array is indexed from
437                   0  to  ARGC - 1.  Dynamically changing the contents of ARGV
438                   can control the files used for data.
439
440       BINMODE     On non-POSIX systems, specifies use of  “binary”  mode  for
441                   all  file  I/O.  Numeric values of 1, 2, or 3, specify that
442                   input files, output  files,  or  all  files,  respectively,
443                   should  use binary I/O.  String values of "r", or "w" spec‐
444                   ify that input files, or output files, respectively, should
445                   use binary I/O.  String values of "rw" or "wr" specify that
446                   all files should use binary I/O.  Any other string value is
447                   treated as "rw", but generates a warning message.
448
449       CONVFMT     The conversion format for numbers, "%.6g", by default.
450
451       ENVIRON     An  array containing the values of the current environment.
452                   The array is indexed by  the  environment  variables,  each
453                   element  being  the  value  of  that  variable (e.g., ENVI‐
454                   RON["HOME"] might be "/home/arnold").
455
456                   In POSIX mode, changing this  array  does  not  affect  the
457                   environment  seen  by  programs which gawk spawns via redi‐
458                   rection or the system() function.  Otherwise, gawk  updates
459                   its  real  environment  so  that programs it spawns see the
460                   changes.
461
462       ERRNO       If a system error occurs either  doing  a  redirection  for
463                   getline,  during  a  read for getline, or during a close(),
464                   then ERRNO is set to a string describing  the  error.   The
465                   value is subject to translation in non-English locales.  If
466                   the string in ERRNO corresponds to a system  error  in  the
467                   errno(3)  variable,  then the numeric value can be found in
468                   PROCINFO["errno"].       For       non-system       errors,
469                   PROCINFO["errno"] will be zero.
470
471       FIELDWIDTHS A  whitespace-separated  list  of  field widths.  When set,
472                   gawk parses the input into fields of fixed  width,  instead
473                   of  using the value of the FS variable as the field separa‐
474                   tor.  Each field width may  optionally  be  preceded  by  a
475                   colon-separated  value  specifying the number of characters
476                   to skip before the field starts.  See Fields, above.
477
478       FILENAME    The name of the current input file.  If no files are speci‐
479                   fied  on  the  command  line, the value of FILENAME is “-”.
480                   However,  FILENAME  is  undefined  inside  the  BEGIN  rule
481                   (unless set by getline).
482
483       FNR         The input record number in the current input file.
484
485       FPAT        A  regular expression describing the contents of the fields
486                   in a record.  When set, gawk parses the input into  fields,
487                   where  the  fields match the regular expression, instead of
488                   using the value of the FS variable as the field  separator.
489                   See Fields, above.
490
491       FS          The input field separator, a space by default.  See Fields,
492                   above.
493
494       FUNCTAB     An array whose indices and  corresponding  values  are  the
495                   names of all the user-defined or extension functions in the
496                   program.  NOTE: You may not use the delete  statement  with
497                   the FUNCTAB array.
498
499       IGNORECASE  Controls the case-sensitivity of all regular expression and
500                   string operations.  If IGNORECASE  has  a  non-zero  value,
501                   then  string  comparisons  and  pattern  matching in rules,
502                   field splitting with FS and FPAT,  record  separating  with
503                   RS, regular expression matching with ~ and !~, and the gen‐
504                   sub(), gsub(), index(), match(), patsplit(),  split(),  and
505                   sub() built-in functions all ignore case when doing regular
506                   expression operations.  NOTE:  Array  subscripting  is  not
507                   affected.   However, the asort() and asorti() functions are
508                   affected.
509                   Thus, if IGNORECASE is not equal to zero, /aB/ matches  all
510                   of the strings "ab", "aB", "Ab", and "AB".  As with all AWK
511                   variables, the initial value of IGNORECASE is zero, so  all
512                   regular expression and string operations are normally case-
513                   sensitive.
514
515       LINT        Provides dynamic control of the --lint option  from  within
516                   an AWK program.  When true, gawk prints lint warnings. When
517                   false,  it  does  not.   When  assigned  the  string  value
518                   "fatal",  lint  warnings  become fatal errors, exactly like
519                   --lint=fatal.  Any other true value just prints warnings.
520
521       NF          The number of fields in the current input record.
522
523       NR          The total number of input records seen so far.
524
525       OFMT        The output format for numbers, "%.6g", by default.
526
527       OFS         The output field separator, a space by default.
528
529       ORS         The output record separator, by default a newline.
530
531       PREC        The working precision of arbitrary precision floating-point
532                   numbers, 53 by default.
533
534       PROCINFO    The  elements  of  this array provide access to information
535                   about the running AWK program.  On some systems, there  may
536                   be  elements  in  the  array, "group1" through "groupn" for
537                   some n, which is the number of  supplementary  groups  that
538                   the  process  has.   Use  the in operator to test for these
539                   elements.  The following  elements  are  guaranteed  to  be
540                   available:
541
542                   PROCINFO["argv"]     The command line arguments as received
543                                        by gawk at the C-language level.   The
544                                        subscripts start from zero.
545
546                   PROCINFO["egid"]     The  value  of  the  getegid(2) system
547                                        call.
548
549                   PROCINFO["errno"]    The value of errno(3)  when  ERRNO  is
550                                        set to the associated error message.
551
552                   PROCINFO["euid"]     The  value  of  the  geteuid(2) system
553                                        call.
554
555                   PROCINFO["FS"]       "FS" if field splitting with FS is  in
556                                        effect, "FPAT" if field splitting with
557                                        FPAT is in  effect,  "FIELDWIDTHS"  if
558                                        field splitting with FIELDWIDTHS is in
559                                        effect, or "API" if API  input  parser
560                                        field splitting is in effect.
561
562                   PROCINFO["gid"]      The  value  of  the  getgid(2)  system
563                                        call.
564
565                   PROCINFO["identifiers"]
566                                        A subarray, indexed by  the  names  of
567                                        all  identifiers  used  in the text of
568                                        the AWK program.  The values  indicate
569                                        what  gawk knows about the identifiers
570                                        after it has finished parsing the pro‐
571                                        gram;  they  are not updated while the
572                                        program runs.   For  each  identifier,
573                                        the value of the element is one of the
574                                        following:
575
576                                        "array"     The   identifier   is   an
577                                                    array.
578
579                                        "builtin"   The identifier is a built-
580                                                    in function.
581
582                                        "extension" The   identifier   is   an
583                                                    extension  function loaded
584                                                    via @load or -l.
585
586                                        "scalar"    The   identifier   is    a
587                                                    scalar.
588
589                                        "untyped"   The  identifier is untyped
590                                                    (could be used as a scalar
591                                                    or   array,  gawk  doesn't
592                                                    know yet).
593
594                                        "user"      The identifier is a  user-
595                                                    defined function.
596
597                   PROCINFO["pgrpid"]   The  process  group  ID of the current
598                                        process.
599
600                   PROCINFO["pid"]      The process ID of the current process.
601
602                   PROCINFO["ppid"]     The parent process ID of  the  current
603                                        process.
604
605                   PROCINFO["strftime"] The  default  time  format  string for
606                                        strftime().
607
608                   PROCINFO["uid"]      The  value  of  the  getuid(2)  system
609                                        call.
610
611                   PROCINFO["version"]  the version of gawk.
612
613                   The  following  elements  are  present  if  loading dynamic
614                   extensions is available:
615
616                   PROCINFO["api_major"]
617                          The major version of the extension API.
618
619                   PROCINFO["api_minor"]
620                          The minor version of the extension API.
621
622                   The following elements are available  if  MPFR  support  is
623                   compiled into gawk:
624
625                   PROCINFO["gmp_version"]
626                          The version of the GNU MP library used for arbitrary
627                          precision number support in gawk.
628
629                   PROCINFO["mpfr_version"]
630                          The version of the GNU MPFR library used  for  arbi‐
631                          trary precision number support in gawk.
632
633                   PROCINFO["prec_max"]
634                          The  maximum  precision  supported  by  the GNU MPFR
635                          library for arbitrary precision floating-point  num‐
636                          bers.
637
638                   PROCINFO["prec_min"]
639                          The  minimum  precision  allowed  by  the  GNU  MPFR
640                          library for arbitrary precision floating-point  num‐
641                          bers.
642
643                   The  following  elements  may  set  by  a program to change
644                   gawk's behavior:
645
646                   PROCINFO["NONFATAL"]
647                          If this exists, then I/O errors for all redirections
648                          become nonfatal.
649
650                   PROCINFO["ame", "NONFATAL"]
651                          Make I/O errors for name be nonfatal.
652
653                   PROCINFO["command", "pty"]
654                          Use a pseudo-tty for two-way communication with com‐
655                          mand instead of setting up two one-way pipes.
656
657                   PROCINFO["input", "READ_TIMEOUT"]
658                          The timeout in milliseconds for  reading  data  from
659                          input,  where  input  is  a  redirection string or a
660                          filename. A value of zero or less than zero means no
661                          timeout.
662
663                   PROCINFO["input", "RETRY"]
664                          If  an  I/O  error  that  may be retried occurs when
665                          reading  data  from  input,  and  this  array  entry
666                          exists, then getline returns -2 instead of following
667                          the default behavior of returning -1 and configuring
668                          input  to return no further data.  An I/O error that
669                          may be retried is one where errno(3) has  the  value
670                          EAGAIN,  EWOULDBLOCK, EINTR, or ETIMEDOUT.  This may
671                          be  useful  in  conjunction  with  PROCINFO["input",
672                          "READ_TIMEOUT"]  or situations where a file descrip‐
673                          tor has been configured to behave in a  non-blocking
674                          fashion.
675
676                   PROCINFO["sorted_in"]
677                          If  this  element exists in PROCINFO, then its value
678                          controls the order in which array elements are  tra‐
679                          versed   in   for   loops.    Supported  values  are
680                          "@ind_str_asc",   "@ind_num_asc",   "@val_type_asc",
681                          "@val_str_asc",   "@val_num_asc",   "@ind_str_desc",
682                          "@ind_num_desc", "@val_type_desc",  "@val_str_desc",
683                          "@val_num_desc",  and  "@unsorted".   The  value can
684                          also be the name (as a  string)  of  any  comparison
685                          function defined as follows:
686
687                               function cmp_func(i1, v1, i2, v2)
688
689                          where  i1  and i2 are the indices, and v1 and v2 are
690                          the corresponding values of the two  elements  being
691                          compared.   It  should  return  a  number less than,
692                          equal to, or greater than 0, depending  on  how  the
693                          elements of the array are to be ordered.
694
695       ROUNDMODE   The rounding mode to use for arbitrary precision arithmetic
696                   on numbers, by default "N" (IEEE-754 roundTiesToEven mode).
697                   The accepted values are "N" or "n" for roundTiesToEven, "U"
698                   or "u" for roundTowardPositive, "D" or "d" for roundToward‐
699                   Negative,  "Z" or "z" for roundTowardZero, and if your ver‐
700                   sion of GNU MPFR library supports it, "A" or "a" for round‐
701                   ing away from zero.
702
703       RS          The input record separator, by default a newline.
704
705       RT          The record terminator.  Gawk sets RT to the input text that
706                   matched the character or regular  expression  specified  by
707                   RS.
708
709       RSTART      The  index  of the first character matched by match(); 0 if
710                   no match.  (This implies that character  indices  start  at
711                   one.)
712
713       RLENGTH     The  length  of  the  string  matched  by match(); -1 if no
714                   match.
715
716       SUBSEP      The character used to separate multiple subscripts in array
717                   elements, by default "\034".
718
719       SYMTAB      An  array  whose  indices  are  the  names of all currently
720                   defined global variables and arrays in  the  program.   The
721                   array  may be used for indirect access to read or write the
722                   value of a variable:
723
724                        foo = 5
725                        SYMTAB["foo"] = 4
726                        print foo    # prints 4
727
728                   The typeof() function may be used to test if an element  in
729                   SYMTAB  is  an array.  You may not use the delete statement
730                   with the SYMTAB array.
731
732       TEXTDOMAIN  The text domain of the AWK program; used to find the local‐
733                   ized translations for the program's strings.
734
735   Arrays
736       Arrays  are  subscripted  with an expression between square brackets ([
737       and ]).  If the expression is an expression list (expr, expr ...)  then
738       the  array subscript is a string consisting of the concatenation of the
739       (string) value of each expression, separated by the value of the SUBSEP
740       variable.   This  facility  is  used  to  simulate multiply dimensioned
741       arrays.  For example:
742
743              i = "A"; j = "B"; k = "C"
744              x[i, j, k] = "hello, world\n"
745
746       assigns the string "hello, world\n" to the element of the array x which
747       is indexed by the string "A\034B\034C".  All arrays in AWK are associa‐
748       tive, i.e., indexed by string values.
749
750       The special operator in may be used to test if an array  has  an  index
751       consisting of a particular value:
752
753              if (val in array)
754                   print array[val]
755
756       If the array has multiple subscripts, use (i, j) in array.
757
758       The in construct may also be used in a for loop to iterate over all the
759       elements of an array.  However, the (i,  j)  in  array  construct  only
760       works in tests, not in for loops.
761
762       An  element  may  be  deleted from an array using the delete statement.
763       The delete statement may also be used to delete the entire contents  of
764       an array, just by specifying the array name without a subscript.
765
766       gawk  supports  true  multidimensional arrays. It does not require that
767       such arrays be ``rectangular'' as in C or C++.  For example:
768
769              a[1] = 5
770              a[2][1] = 6
771              a[2][2] = 7
772
773       NOTE: You may need to tell gawk that an array element is really a  sub‐
774       array  in  order  to use it where gawk expects an array (such as in the
775       second argument to split()).  You can do this by creating an element in
776       the subarray and then deleting it with the delete statement.
777
778   Variable Typing And Conversion
779       Variables  and  fields  may be (floating point) numbers, or strings, or
780       both.  They may also be regular expressions. How the value of  a  vari‐
781       able  is  interpreted  depends  upon its context.  If used in a numeric
782       expression, it will be treated as a number; if used as a string it will
783       be treated as a string.
784
785       To force a variable to be treated as a number, add zero to it; to force
786       it to be treated as a string, concatenate it with the null string.
787
788       Uninitialized variables have the numeric  value  zero  and  the  string
789       value "" (the null, or empty, string).
790
791       When  a  string must be converted to a number, the conversion is accom‐
792       plished using strtod(3).  A number is converted to a  string  by  using
793       the  value  of  CONVFMT  as  a  format  string for sprintf(3), with the
794       numeric value of the variable as the argument.   However,  even  though
795       all  numbers in AWK are floating-point, integral values are always con‐
796       verted as integers.  Thus, given
797
798              CONVFMT = "%2.2f"
799              a = 12
800              b = a ""
801
802       the variable b has a string value of "12" and not "12.00".
803
804       NOTE: When operating in POSIX mode (such as with the  --posix  option),
805       beware  that locale settings may interfere with the way decimal numbers
806       are treated: the decimal separator of the numbers you  are  feeding  to
807       gawk  must  conform to what your locale would expect, be it a comma (,)
808       or a period (.).
809
810       Gawk performs comparisons as follows: If  two  variables  are  numeric,
811       they  are  compared numerically.  If one value is numeric and the other
812       has a string value that is a “numeric  string,”  then  comparisons  are
813       also  done numerically.  Otherwise, the numeric value is converted to a
814       string and a string comparison is performed.  Two strings are compared,
815       of course, as strings.
816
817       Note that string constants, such as "57", are not numeric strings, they
818       are string constants.  The idea of “numeric  string”  only  applies  to
819       fields,  getline  input,  FILENAME, ARGV elements, ENVIRON elements and
820       the elements of an array created by  split()  or  patsplit()  that  are
821       numeric  strings.   The  basic  idea  is that user input, and only user
822       input, that looks numeric, should be treated that way.
823
824   Octal and Hexadecimal Constants
825       You may use C-style octal and hexadecimal constants in your AWK program
826       source  code.   For example, the octal value 011 is equal to decimal 9,
827       and the hexadecimal value 0x11 is equal to decimal 17.
828
829   String Constants
830       String constants in AWK are sequences of  characters  enclosed  between
831       double quotes (like "value").  Within strings, certain escape sequences
832       are recognized, as in C.  These are:
833
834       \\   A literal backslash.
835
836       \a   The “alert” character; usually the ASCII BEL character.
837
838       \b   Backspace.
839
840       \f   Form-feed.
841
842       \n   Newline.
843
844       \r   Carriage return.
845
846       \t   Horizontal tab.
847
848       \v   Vertical tab.
849
850       \xhex digits
851            The character represented by the string of hexadecimal digits fol‐
852            lowing the \x.  Up to two following hexadecimal digits are consid‐
853            ered part of the escape sequence.  E.g., "\x1B" is the  ASCII  ESC
854            (escape) character.
855
856       \ddd The  character  represented  by the 1-, 2-, or 3-digit sequence of
857            octal digits.  E.g., "\033" is the ASCII ESC (escape) character.
858
859       \c   The literal character c.
860
861       In compatibility mode, the characters represented by octal and hexadec‐
862       imal  escape  sequences  are  treated  literally  when  used in regular
863       expression constants.  Thus, /a\52b/ is equivalent to /a\*b/.
864
865   Regexp Constants
866       A regular expression constant is  a  sequence  of  characters  enclosed
867       between forward slashes (like /value/).  Regular expression matching is
868       described more fully below; see Regular Expressions.
869
870       The escape sequences described earlier may also be used inside constant
871       regular  expressions  (e.g., /[ \t\f\n\r\v]/ matches whitespace charac‐
872       ters).
873
874       Gawk   provides strongly typed regular expression constants. These  are
875              written  with a leading @ symbol (like so: @/value/).  Such con‐
876              stants may be assigned to scalars  (variables,  array  elements)
877              and  passed  to user-defined functions. Variables that have been
878              so assigned have regular expression type.
879

PATTERNS AND ACTIONS

881       AWK is a line-oriented language.  The pattern comes first, and then the
882       action.  Action statements are enclosed in { and }.  Either the pattern
883       may be missing, or the action may be missing, but, of course, not both.
884       If  the pattern is missing, the action executes for every single record
885       of input.  A missing action is equivalent to
886
887              { print }
888
889       which prints the entire record.
890
891       Comments begin with the # character, and continue until the end of  the
892       line.   Empty  lines  may  be used to separate statements.  Normally, a
893       statement ends with a newline, however, this is not the case for  lines
894       ending in a comma, {, ?, :, &&, or ||.  Lines ending in do or else also
895       have their statements automatically continued on  the  following  line.
896       In  other  cases,  a  line can be continued by ending it with a “\”, in
897       which case the newline is ignored.
898
899       Multiple statements may be put on one line by separating  them  with  a
900       “;”.   This  applies to both the statements within the action part of a
901       pattern-action pair (the usual case), and to the pattern-action  state‐
902       ments themselves.
903
904   Patterns
905       AWK patterns may be one of the following:
906
907              BEGIN
908              END
909              BEGINFILE
910              ENDFILE
911              /regular expression/
912              relational expression
913              pattern && pattern
914              pattern || pattern
915              pattern ? pattern : pattern
916              (pattern)
917              ! pattern
918              pattern1, pattern2
919
920       BEGIN  and  END  are two special kinds of patterns which are not tested
921       against the input.  The action parts of all BEGIN patterns  are  merged
922       as if all the statements had been written in a single BEGIN rule.  They
923       are executed before any of the input is read.  Similarly, all  the  END
924       rules are merged, and executed when all the input is exhausted (or when
925       an exit statement is executed).  BEGIN and END patterns cannot be  com‐
926       bined  with  other patterns in pattern expressions.  BEGIN and END pat‐
927       terns cannot have missing action parts.
928
929       BEGINFILE and ENDFILE are additional special patterns whose bodies  are
930       executed  before  reading  the  first record of each command line input
931       file and after reading the last record of each file.  Inside the BEGIN‐
932       FILE  rule,  the  value  of  ERRNO  is the empty string if the file was
933       opened successfully.  Otherwise, there is some problem  with  the  file
934       and  the code should use nextfile to skip it. If that is not done, gawk
935       produces its usual fatal error for files that cannot be opened.
936
937       For /regular expression/ patterns, the associated statement is executed
938       for  each  input  record  that matches the regular expression.  Regular
939       expressions are the same as  those  in  egrep(1),  and  are  summarized
940       below.
941
942       A  relational  expression may use any of the operators defined below in
943       the section on actions.  These generally test  whether  certain  fields
944       match certain regular expressions.
945
946       The  &&,  ||, and !  operators are logical AND, logical OR, and logical
947       NOT, respectively, as in C.  They do short-circuit evaluation, also  as
948       in  C,  and  are used for combining more primitive pattern expressions.
949       As in most languages, parentheses may be used to change  the  order  of
950       evaluation.
951
952       The  ?:  operator is like the same operator in C.  If the first pattern
953       is true then the pattern used for testing is the second pattern, other‐
954       wise  it  is  the  third.  Only one of the second and third patterns is
955       evaluated.
956
957       The pattern1, pattern2 form of an expression is called a range pattern.
958       It  matches  all input records starting with a record that matches pat‐
959       tern1, and continuing until a record that matches pattern2,  inclusive.
960       It does not combine with any other sort of pattern expression.
961
962   Regular Expressions
963       Regular  expressions  are  the  extended kind found in egrep.  They are
964       composed of characters as follows:
965
966       c          Matches the non-metacharacter c.
967
968       \c         Matches the literal character c.
969
970       .          Matches any character including newline.
971
972       ^          Matches the beginning of a string.
973
974       $          Matches the end of a string.
975
976       [abc...]   A character list: matches any of the characters abc....  You
977                  may  include a range of characters by separating them with a
978                  dash.
979
980       [^abc...]  A negated  character  list:  matches  any  character  except
981                  abc....
982
983       r1|r2      Alternation: matches either r1 or r2.
984
985       r1r2       Concatenation: matches r1, and then r2.
986
987       r+         Matches one or more r's.
988
989       r*         Matches zero or more r's.
990
991       r?         Matches zero or one r's.
992
993       (r)        Grouping: matches r.
994
995       r{n}
996       r{n,}
997       r{n,m}     One  or two numbers inside braces denote an interval expres‐
998                  sion.  If there is one number in the braces,  the  preceding
999                  regular  expression r is repeated n times.  If there are two
1000                  numbers separated by a comma, r is repeated n  to  m  times.
1001                  If  there  is  one  number  followed  by  a comma, then r is
1002                  repeated at least n times.
1003
1004       \y         Matches the empty string at either the beginning or the  end
1005                  of a word.
1006
1007       \B         Matches the empty string within a word.
1008
1009       \<         Matches the empty string at the beginning of a word.
1010
1011       \>         Matches the empty string at the end of a word.
1012
1013       \s         Matches any whitespace character.
1014
1015       \S         Matches any nonwhitespace character.
1016
1017       \w         Matches  any  word-constituent  character (letter, digit, or
1018                  underscore).
1019
1020       \W         Matches any character that is not word-constituent.
1021
1022       \`         Matches the empty  string  at  the  beginning  of  a  buffer
1023                  (string).
1024
1025       \'         Matches the empty string at the end of a buffer.
1026
1027       The  escape  sequences  that  are valid in string constants (see String
1028       Constants) are also valid in regular expressions.
1029
1030       Character classes are a feature introduced in the  POSIX  standard.   A
1031       character  class  is a special notation for describing lists of charac‐
1032       ters that have a specific attribute, but where  the  actual  characters
1033       themselves  can  vary from country to country and/or from character set
1034       to character set.  For example, the notion of  what  is  an  alphabetic
1035       character differs in the USA and in France.
1036
1037       A  character  class  is  only  valid in a regular expression inside the
1038       brackets of a character list.  Character classes consist of [:, a  key‐
1039       word  denoting the class, and :].  The character classes defined by the
1040       POSIX standard are:
1041
1042       [:alnum:]  Alphanumeric characters.
1043
1044       [:alpha:]  Alphabetic characters.
1045
1046       [:blank:]  Space or tab characters.
1047
1048       [:cntrl:]  Control characters.
1049
1050       [:digit:]  Numeric characters.
1051
1052       [:graph:]  Characters that are both printable and visible.  (A space is
1053                  printable, but not visible, while an a is both.)
1054
1055       [:lower:]  Lowercase alphabetic characters.
1056
1057       [:print:]  Printable  characters (characters that are not control char‐
1058                  acters.)
1059
1060       [:punct:]  Punctuation characters (characters that are not letter, dig‐
1061                  its, control characters, or space characters).
1062
1063       [:space:]  Space  characters (such as space, tab, and formfeed, to name
1064                  a few).
1065
1066       [:upper:]  Uppercase alphabetic characters.
1067
1068       [:xdigit:] Characters that are hexadecimal digits.
1069
1070       For example, before the POSIX standard, to match  alphanumeric  charac‐
1071       ters, you would have had to write /[A-Za-z0-9]/.  If your character set
1072       had other alphabetic characters in it, this would not match  them,  and
1073       if  your  character set collated differently from ASCII, this might not
1074       even match the ASCII alphanumeric characters.  With the POSIX character
1075       classes,  you  can write /[[:alnum:]]/, and this matches the alphabetic
1076       and numeric characters in your character set, no matter what it is.
1077
1078       Two additional special sequences can appear in character lists.   These
1079       apply  to  non-ASCII  character  sets,  which  can  have single symbols
1080       (called collating elements) that are represented  with  more  than  one
1081       character,  as  well as several characters that are equivalent for col‐
1082       lating, or sorting, purposes.  (E.g., in French,  a  plain  “e”  and  a
1083       grave-accented “e`” are equivalent.)
1084
1085       Collating Symbols
1086              A  collating  symbol  is  a  multi-character  collating  element
1087              enclosed in [.  and .].  For example, if ch is a collating  ele‐
1088              ment,  then  [[.ch.]]  is a regular expression that matches this
1089              collating element, while  [ch]  is  a  regular  expression  that
1090              matches either c or h.
1091
1092       Equivalence Classes
1093              An  equivalence  class  is  a locale-specific name for a list of
1094              characters that are equivalent.  The name is enclosed in [=  and
1095              =].   For  example, the name e might be used to represent all of
1096              “e”, “e´”, and “e`”.  In this case, [[=e=]] is a  regular  expres‐
1097              sion that matches any of e, e´, or e`.
1098
1099       These  features are very valuable in non-English speaking locales.  The
1100       library functions that gawk uses for regular expression  matching  cur‐
1101       rently  only  recognize  POSIX character classes; they do not recognize
1102       collating symbols or equivalence classes.
1103
1104       The \y, \B, \<, \>, \s, \S, \w, \W, \`, and \' operators  are  specific
1105       to  gawk;  they  are  extensions based on facilities in the GNU regular
1106       expression libraries.
1107
1108       The various command line options control how gawk interprets characters
1109       in regular expressions.
1110
1111       No options
1112              In  the  default case, gawk provides all the facilities of POSIX
1113              regular expressions and the  GNU  regular  expression  operators
1114              described above.
1115
1116       --posix
1117              Only  POSIX regular expressions are supported, the GNU operators
1118              are not special.  (E.g., \w matches a literal w).
1119
1120       --traditional
1121              Traditional UNIX awk regular expressions are matched.   The  GNU
1122              operators  are  not  special,  and  interval expressions are not
1123              available.  Characters described by octal and hexadecimal escape
1124              sequences  are treated literally, even if they represent regular
1125              expression metacharacters.
1126
1127       --re-interval
1128              Allow interval  expressions  in  regular  expressions,  even  if
1129              --traditional has been provided.
1130
1131   Actions
1132       Action  statements  are enclosed in braces, { and }.  Action statements
1133       consist of the usual assignment, conditional,  and  looping  statements
1134       found  in  most  languages.   The  operators,  control  statements, and
1135       input/output statements available are patterned after those in C.
1136
1137   Operators
1138       The operators in AWK, in order of decreasing precedence, are:
1139
1140       (...)       Grouping
1141
1142       $           Field reference.
1143
1144       ++ --       Increment and decrement, both prefix and postfix.
1145
1146       ^           Exponentiation (** may  also  be  used,  and  **=  for  the
1147                   assignment operator).
1148
1149       + - !       Unary plus, unary minus, and logical negation.
1150
1151       * / %       Multiplication, division, and modulus.
1152
1153       + -         Addition and subtraction.
1154
1155       space       String concatenation.
1156
1157       |   |&      Piped I/O for getline, print, and printf.
1158
1159       < > <= >= == !=
1160                   The regular relational operators.
1161
1162       ~ !~        Regular  expression match, negated match.  NOTE: Do not use
1163                   a constant regular expression (/foo/) on the left-hand side
1164                   of  a  ~  or !~.  Only use one on the right-hand side.  The
1165                   expression /foo/ ~ exp has  the  same  meaning  as  (($0  ~
1166                   /foo/) ~ exp).  This is usually not what you want.
1167
1168       in          Array membership.
1169
1170       &&          Logical AND.
1171
1172       ||          Logical OR.
1173
1174       ?:          The  C  conditional  expression.  This has the form expr1 ?
1175                   expr2 : expr3.  If expr1 is true, the value of the  expres‐
1176                   sion  is  expr2,  otherwise it is expr3.  Only one of expr2
1177                   and expr3 is evaluated.
1178
1179       = += -= *= /= %= ^=
1180                   Assignment.  Both absolute assignment  (var  =  value)  and
1181                   operator-assignment (the other forms) are supported.
1182
1183   Control Statements
1184       The control statements are as follows:
1185
1186              if (condition) statement [ else statement ]
1187              while (condition) statement
1188              do statement while (condition)
1189              for (expr1; expr2; expr3) statement
1190              for (var in array) statement
1191              break
1192              continue
1193              delete array[index]
1194              delete array
1195              exit [ expression ]
1196              { statements }
1197              switch (expression) {
1198              case value|regex : statement
1199              ...
1200              [ default: statement ]
1201              }
1202
1203   I/O Statements
1204       The input/output statements are as follows:
1205
1206       close(file [, how])   Close  file, pipe or coprocess.  The optional how
1207                             should only be used when closing  one  end  of  a
1208                             two-way pipe to a coprocess.  It must be a string
1209                             value, either "to" or "from".
1210
1211       getline               Set $0 from next input record; set NF,  NR,  FNR,
1212                             RT.
1213
1214       getline <file         Set $0 from next record of file; set NF, RT.
1215
1216       getline var           Set var from next input record; set NR, FNR, RT.
1217
1218       getline var <file     Set var from next record of file, RT.
1219
1220       command | getline [var]
1221                             Run  command  piping the output either into $0 or
1222                             var, as above, and RT.
1223
1224       command |& getline [var]
1225                             Run command as  a  coprocess  piping  the  output
1226                             either  into $0 or var, as above, and RT.  Copro‐
1227                             cesses are a gawk extension.  (command  can  also
1228                             be  a  socket.   See  the subsection Special File
1229                             Names, below.)
1230
1231       next                  Stop processing the current  input  record.   The
1232                             next  input  record is read and processing starts
1233                             over with the first pattern in the  AWK  program.
1234                             Upon  reaching  the  end  of the input data, gawk
1235                             executes any END rule(s).
1236
1237       nextfile              Stop processing the current input file.  The next
1238                             input record read comes from the next input file.
1239                             FILENAME and ARGIND are updated, FNR is reset  to
1240                             1, and processing starts over with the first pat‐
1241                             tern in the AWK program.  Upon reaching  the  end
1242                             of  the input data, gawk executes any ENDFILE and
1243                             END rule(s).
1244
1245       print                 Print the current record.  The output  record  is
1246                             terminated with the value of ORS.
1247
1248       print expr-list       Print  expressions.  Each expression is separated
1249                             by the value of OFS.  The output record is termi‐
1250                             nated with the value of ORS.
1251
1252       print expr-list >file Print  expressions  on  file.  Each expression is
1253                             separated by the value of OFS.  The output record
1254                             is terminated with the value of ORS.
1255
1256       printf fmt, expr-list Format  and  print.   See  The  printf Statement,
1257                             below.
1258
1259       printf fmt, expr-list >file
1260                             Format and print on file.
1261
1262       system(cmd-line)      Execute the command cmd-line, and return the exit
1263                             status.   (This may not be available on non-POSIX
1264                             systems.)  See GAWK:  Effective  AWK  Programming
1265                             for the full details on the exit status.
1266
1267       fflush([file])        Flush any buffers associated with the open output
1268                             file or pipe file.  If file is missing or  if  it
1269                             is  the  null  string, then flush all open output
1270                             files and pipes.
1271
1272       Additional output redirections are allowed for print and printf.
1273
1274       print ... >> file
1275              Appends output to the file.
1276
1277       print ... | command
1278              Writes on a pipe.
1279
1280       print ... |& command
1281              Sends data to a coprocess or socket.  (See also  the  subsection
1282              Special File Names, below.)
1283
1284       The  getline  command returns 1 on success, zero on end of file, and -1
1285       on an error.  If the errno(3) value indicates that  the  I/O  operation
1286       may  be  retried,  and  PROCINFO["input",  "RETRY"]  is set, then -2 is
1287       returned instead of -1, and further calls to getline may be  attempted.
1288       Upon an error, ERRNO is set to a string describing the problem.
1289
1290       NOTE:  Failure in opening a two-way socket results in a non-fatal error
1291       being returned to the calling function. If using a pipe, coprocess,  or
1292       socket  to getline, or from print or printf within a loop, you must use
1293       close() to create new instances of the command or socket.  AWK does not
1294       automatically  close  pipes,  sockets,  or coprocesses when they return
1295       EOF.
1296
1297   The printf Statement
1298       The AWK versions of the printf statement and  sprintf()  function  (see
1299       below) accept the following conversion specification formats:
1300
1301       %c      A single character.  If the argument used for %c is numeric, it
1302               is treated as a character and printed.  Otherwise, the argument
1303               is assumed to be a string, and the only first character of that
1304               string is printed.
1305
1306       %d, %i  A decimal number (the integer part).
1307
1308       %e, %E  A floating point number of the form [-]d.dddddde[+-]dd.  The %E
1309               format uses E instead of e.
1310
1311       %f, %F  A floating point number of the form [-]ddd.dddddd.  If the sys‐
1312               tem library supports it, %F is available as well. This is  like
1313               %f,  but  uses  capital  letters for special “not a number” and
1314               “infinity” values. If %F is not available, gawk uses %f.
1315
1316       %g, %G  Use %e or %f conversion, whichever is shorter, with nonsignifi‐
1317               cant zeros suppressed.  The %G format uses %E instead of %e.
1318
1319       %o      An unsigned octal number (also an integer).
1320
1321       %u      An unsigned decimal number (again, an integer).
1322
1323       %s      A character string.
1324
1325       %x, %X  An  unsigned  hexadecimal  number  (an integer).  The %X format
1326               uses ABCDEF instead of abcdef.
1327
1328       %%      A single % character; no argument is converted.
1329
1330       Optional, additional parameters may lie between the % and  the  control
1331       letter:
1332
1333       count$ Use the count'th argument at this point in the formatting.  This
1334              is called a positional specifier and is intended  primarily  for
1335              use  in translated versions of format strings, not in the origi‐
1336              nal text of an AWK program.  It is a gawk extension.
1337
1338       -      The expression should be left-justified within its field.
1339
1340       space  For numeric conversions, prefix positive values  with  a  space,
1341              and negative values with a minus sign.
1342
1343       +      The  plus sign, used before the width modifier (see below), says
1344              to always supply a sign for numeric  conversions,  even  if  the
1345              data  to  be  formatted  is positive.  The + overrides the space
1346              modifier.
1347
1348       #      Use an “alternate form” for certain control  letters.   For  %o,
1349              supply  a  leading zero.  For %x, and %X, supply a leading 0x or
1350              0X for a nonzero result.  For %e, %E,  %f  and  %F,  the  result
1351              always contains a decimal point.  For %g, and %G, trailing zeros
1352              are not removed from the result.
1353
1354       0      A leading 0 (zero) acts as a flag, indicating that output should
1355              be  padded  with zeroes instead of spaces.  This applies only to
1356              the numeric output formats.  This flag only has an  effect  when
1357              the field width is wider than the value to be printed.
1358
1359       '      A  single  quote character instructs gawk to insert the locale's
1360              thousands-separator character into decimal numbers, and to  also
1361              use  the  locale's  decimal  point character with floating point
1362              formats.  This requires correct locale support in the C  library
1363              and in the definition of the current locale.
1364
1365       width  The field should be padded to this width.  The field is normally
1366              padded with spaces.  With the 0 flag, it is padded with zeroes.
1367
1368       .prec  A number that specifies the precision to use when printing.  For
1369              the  %e,  %E,  %f  and %F, formats, this specifies the number of
1370              digits you want printed to the right of the decimal point.   For
1371              the  %g, and %G formats, it specifies the maximum number of sig‐
1372              nificant digits.  For the %d, %i, %o, %u, %x, and %X formats, it
1373              specifies  the  minimum  number  of digits to print.  For %s, it
1374              specifies the maximum number of characters from the string  that
1375              should be printed.
1376
1377       The  dynamic width and prec capabilities of the ISO C printf() routines
1378       are supported.  A * in place of either the width or prec specifications
1379       causes  their  values  to  be taken from the argument list to printf or
1380       sprintf().  To use a positional specifier with a dynamic width or  pre‐
1381       cision,  supply the count$ after the * in the format string.  For exam‐
1382       ple, "%3$*2$.*1$s".
1383
1384   Special File Names
1385       When doing I/O redirection from either print or printf into a file,  or
1386       via  getline  from  a  file,  gawk recognizes certain special filenames
1387       internally.  These filenames allow  access  to  open  file  descriptors
1388       inherited  from  gawk's parent process (usually the shell).  These file
1389       names may also be used on the command line to  name  data  files.   The
1390       filenames are:
1391
1392       -           The standard input.
1393
1394       /dev/stdin  The standard input.
1395
1396       /dev/stdout The standard output.
1397
1398       /dev/stderr The standard error output.
1399
1400       /dev/fd/n   The file associated with the open file descriptor n.
1401
1402       These are particularly useful for error messages.  For example:
1403
1404              print "You blew it!" > "/dev/stderr"
1405
1406       whereas you would otherwise have to use
1407
1408              print "You blew it!" | "cat 1>&2"
1409
1410       The following special filenames may be used with the |& coprocess oper‐
1411       ator for creating TCP/IP network connections:
1412
1413       /inet/tcp/lport/rhost/rport
1414       /inet4/tcp/lport/rhost/rport
1415       /inet6/tcp/lport/rhost/rport
1416              Files for a TCP/IP connection on local port lport to remote host
1417              rhost  on remote port rport.  Use a port of 0 to have the system
1418              pick a port.  Use /inet4 to force an IPv4 connection, and /inet6
1419              to  force  an  IPv6  connection.   Plain  /inet  uses the system
1420              default (most likely IPv4).
1421
1422       /inet/udp/lport/rhost/rport
1423       /inet4/udp/lport/rhost/rport
1424       /inet6/udp/lport/rhost/rport
1425              Similar, but use UDP/IP instead of TCP/IP.
1426
1427   Numeric Functions
1428       AWK has the following built-in arithmetic functions:
1429
1430       atan2(y, x)   Return the arctangent of y/x in radians.
1431
1432       cos(expr)     Return the cosine of expr, which is in radians.
1433
1434       exp(expr)     The exponential function.
1435
1436       int(expr)     Truncate to integer.
1437
1438       log(expr)     The natural logarithm function.
1439
1440       rand()        Return a random number N, between zero and one, such that
1441                     0 ≤ N < 1.
1442
1443       sin(expr)     Return the sine of expr, which is in radians.
1444
1445       sqrt(expr)    Return the square root of expr.
1446
1447       srand([expr]) Use expr as the new seed for the random number generator.
1448                     If no expr is provided, use the time of day.  Return  the
1449                     previous seed for the random number generator.
1450
1451   String Functions
1452       Gawk has the following built-in string functions:
1453
1454       asort(s [, d [, how] ]) Return  the  number  of  elements in the source
1455                               array s.  Sort the contents of s  using  gawk's
1456                               normal  rules for comparing values, and replace
1457                               the indices of the sorted values s with sequen‐
1458                               tial  integers starting with 1. If the optional
1459                               destination array d is specified, first  dupli‐
1460                               cate  s  into  d,  and then sort d, leaving the
1461                               indices of the source array  s  unchanged.  The
1462                               optional  string how controls the direction and
1463                               the comparison mode.  Valid values for how  are
1464                               any     of     the     strings     valid    for
1465                               PROCINFO["sorted_in"].  It can also be the name
1466                               of   a   user-defined  comparison  function  as
1467                               described in PROCINFO["sorted_in"].
1468
1469       asorti(s [, d [, how] ])
1470                               Return the number of  elements  in  the  source
1471                               array  s.   The behavior is the same as that of
1472                               asort(), except that the array indices are used
1473                               for  sorting, not the array values.  When done,
1474                               the array is indexed numerically, and the  val‐
1475                               ues  are  those  of  the original indices.  The
1476                               original values are lost; thus provide a second
1477                               array  if  you  wish  to preserve the original.
1478                               The purpose of the optional string how  is  the
1479                               same as described previously for asort().
1480
1481       gensub(r, s, h [, t])   Search  the  target string t for matches of the
1482                               regular expression r.  If h is a string  begin‐
1483                               ning with g or G, then replace all matches of r
1484                               with s.  Otherwise, h is  a  number  indicating
1485                               which  match of r to replace.  If t is not sup‐
1486                               plied, use $0 instead.  Within the  replacement
1487                               text  s,  the  sequence  \n, where n is a digit
1488                               from 1 to 9, may be used to indicate  just  the
1489                               text that matched the n'th parenthesized subex‐
1490                               pression.   The  sequence  \0  represents   the
1491                               entire  matched  text, as does the character &.
1492                               Unlike sub() and gsub(), the modified string is
1493                               returned as the result of the function, and the
1494                               original target string is not changed.
1495
1496       gsub(r, s [, t])        For each substring matching the regular expres‐
1497                               sion  r  in the string t, substitute the string
1498                               s, and return the number of substitutions.   If
1499                               t  is  not  supplied,  use  $0.   An  &  in the
1500                               replacement text is replaced with the text that
1501                               was  actually matched.  Use \& to get a literal
1502                               &.  (This must be typed  as  "\\&";  see  GAWK:
1503                               Effective  AWK Programming for a fuller discus‐
1504                               sion of the  rules  for  ampersands  and  back‐
1505                               slashes  in  the  replacement  text  of  sub(),
1506                               gsub(), and gensub().)
1507
1508       index(s, t)             Return the index of the string t in the  string
1509                               s,  or zero if t is not present.  (This implies
1510                               that character indices start at one.)  It is  a
1511                               fatal error to use a regexp constant for t.
1512
1513       length([s])             Return  the  length  of  the  string  s, or the
1514                               length of $0 if s is not supplied.  As  a  non-
1515                               standard  extension,  with  an  array argument,
1516                               length() returns the number of elements in  the
1517                               array.
1518
1519       match(s, r [, a])       Return  the  position  in  s  where the regular
1520                               expression r  occurs,  or  zero  if  r  is  not
1521                               present,  and  set  the  values  of  RSTART and
1522                               RLENGTH.  Note that the argument order  is  the
1523                               same as for the ~ operator: str ~ re.  If array
1524                               a is provided, a is cleared and then elements 1
1525                               through  n  are  filled  with the portions of s
1526                               that match the corresponding parenthesized sub‐
1527                               expression in r.  The zero'th element of a con‐
1528                               tains the portion of s matched  by  the  entire
1529                               regular    expression   r.    Subscripts   a[n,
1530                               "start"], and a[n, "length"] provide the start‐
1531                               ing  index  in  the  string  and length respec‐
1532                               tively, of each matching substring.
1533
1534       patsplit(s, a [, r [, seps] ])
1535                               Split the string s into the  array  a  and  the
1536                               separators array seps on the regular expression
1537                               r, and return the number  of  fields.   Element
1538                               values  are  the  portions of s that matched r.
1539                               The value of seps[i] is the possibly null sepa‐
1540                               rator  that  appeared after a[i].  The value of
1541                               seps[0] is the possibly null leading separator.
1542                               If  r  is  omitted,  FPAT is used instead.  The
1543                               arrays a and seps are cleared first.  Splitting
1544                               behaves  identically  to  field  splitting with
1545                               FPAT, described above.
1546
1547       split(s, a [, r [, seps] ])
1548                               Split the string s into the  array  a  and  the
1549                               separators array seps on the regular expression
1550                               r, and return the number of fields.   If  r  is
1551                               omitted,  FS is used instead.  The arrays a and
1552                               seps are cleared first.  seps[i] is  the  field
1553                               separator matched by r between a[i] and a[i+1].
1554                               If r is a single space, then leading whitespace
1555                               in  s goes into the extra array element seps[0]
1556                               and trailing whitespace  goes  into  the  extra
1557                               array  element  seps[n],  where n is the return
1558                               value  of  split(s,  a,  r,  seps).   Splitting
1559                               behaves   identically   to   field   splitting,
1560                               described above.
1561
1562       sprintf(fmt, expr-list) Print expr-list according to  fmt,  and  return
1563                               the resulting string.
1564
1565       strtonum(str)           Examine  str, and return its numeric value.  If
1566                               str begins with a leading 0,  treat  it  as  an
1567                               octal  number.  If str begins with a leading 0x
1568                               or 0X, treat it as a hexadecimal number.   Oth‐
1569                               erwise, assume it is a decimal number.
1570
1571       sub(r, s [, t])         Just  like  gsub(),  but replace only the first
1572                               matching substring.  Return either zero or one.
1573
1574       substr(s, i [, n])      Return the at most n-character substring  of  s
1575                               starting  at  i.  If n is omitted, use the rest
1576                               of s.
1577
1578       tolower(str)            Return a copy of the string str, with  all  the
1579                               uppercase characters in str translated to their
1580                               corresponding  lowercase  counterparts.    Non-
1581                               alphabetic characters are left unchanged.
1582
1583       toupper(str)            Return  a  copy of the string str, with all the
1584                               lowercase characters in str translated to their
1585                               corresponding   uppercase  counterparts.   Non-
1586                               alphabetic characters are left unchanged.
1587
1588       Gawk is multibyte aware.  This means that index(),  length(),  substr()
1589       and match() all work in terms of characters, not bytes.
1590
1591   Time Functions
1592       Since  one  of the primary uses of AWK programs is processing log files
1593       that contain time stamp information, gawk provides the following  func‐
1594       tions for obtaining time stamps and formatting them.
1595
1596       mktime(datespec [, utc-flag])
1597                 Turn  datespec into a time stamp of the same form as returned
1598                 by systime(), and return  the  result.   The  datespec  is  a
1599                 string  of  the form YYYY MM DD HH MM SS[ DST].  The contents
1600                 of the string are six or seven numbers  representing  respec‐
1601                 tively  the  full year including century, the month from 1 to
1602                 12, the day of the month from 1 to 31, the hour  of  the  day
1603                 from  0  to 23, the minute from 0 to 59, the second from 0 to
1604                 60, and an optional daylight  saving  flag.   The  values  of
1605                 these  numbers  need  not be within the ranges specified; for
1606                 example, an hour of -1 means 1  hour  before  midnight.   The
1607                 origin-zero  Gregorian  calendar is assumed, with year 0 pre‐
1608                 ceding year 1 and year -1 preceding year 0.  If  utc-flag  is
1609                 present  and  is non-zero or non-null, the time is assumed to
1610                 be in the UTC time zone; otherwise, the time is assumed to be
1611                 in  the  local time zone.  If the DST daylight saving flag is
1612                 positive, the time is assumed to be daylight saving time;  if
1613                 zero,  the  time is assumed to be standard time; and if nega‐
1614                 tive (the default), mktime() attempts  to  determine  whether
1615                 daylight saving time is in effect for the specified time.  If
1616                 datespec does not contain enough elements or if the resulting
1617                 time is out of range, mktime() returns -1.
1618
1619       strftime([format [, timestamp[, utc-flag]]])
1620                 Format  timestamp  according  to the specification in format.
1621                 If utc-flag is present  and  is  non-zero  or  non-null,  the
1622                 result is in UTC, otherwise the result is in local time.  The
1623                 timestamp should be of the same  form  as  returned  by  sys‐
1624                 time().   If timestamp is missing, the current time of day is
1625                 used.  If format is missing, a default format  equivalent  to
1626                 the  output of date(1) is used.  The default format is avail‐
1627                 able in PROCINFO["strftime"].  See the specification for  the
1628                 strftime()  function in ISO C for the format conversions that
1629                 are guaranteed to be available.
1630
1631       systime() Return the current time of day as the number of seconds since
1632                 the Epoch (1970-01-01 00:00:00 UTC on POSIX systems).
1633
1634   Bit Manipulations Functions
1635       Gawk  supplies  the following bit manipulation functions.  They work by
1636       converting double-precision floating point values  to  uintmax_t  inte‐
1637       gers,  doing  the  operation,  and  then  converting the result back to
1638       floating point.
1639
1640       NOTE: Passing negative operands to any  of  these  functions  causes  a
1641       fatal error.
1642
1643       The functions are:
1644
1645       and(v1, v2 [, ...]) Return  the  bitwise  AND of the values provided in
1646                           the argument list.  There must be at least two.
1647
1648       compl(val)          Return the bitwise complement of val.
1649
1650       lshift(val, count)  Return the value of  val,  shifted  left  by  count
1651                           bits.
1652
1653       or(v1, v2 [, ...])  Return the bitwise OR of the values provided in the
1654                           argument list.  There must be at least two.
1655
1656       rshift(val, count)  Return the value of val,  shifted  right  by  count
1657                           bits.
1658
1659       xor(v1, v2 [, ...]) Return  the  bitwise  XOR of the values provided in
1660                           the argument list.  There must be at least two.
1661
1662   Type Functions
1663       The following function is for use with multidimensional arrays.
1664
1665       isarray(x)
1666              Return true if x is an array, false otherwise.
1667
1668       You can tell the type of any variable or array element with the follow‐
1669       ing function:
1670
1671       typeof(x)
1672              Return  a  string  indicating the type of x.  The string will be
1673              one of  "array",  "number",  "regexp",  "string",  "strnum",  or
1674              "undefined".
1675
1676   Internationalization Functions
1677       The  following  functions  may be used from within your AWK program for
1678       translating strings at run-time.  For full details, see GAWK: Effective
1679       AWK Programming.
1680
1681       bindtextdomain(directory [, domain])
1682              Specify  the  directory  where gawk looks for the .gmo files, in
1683              case they will not or cannot be placed in the ``standard'' loca‐
1684              tions  (e.g.,  during  testing).  It returns the directory where
1685              domain is ``bound.''
1686              The default domain is the value of TEXTDOMAIN.  If directory  is
1687              the  null string (""), then bindtextdomain() returns the current
1688              binding for the given domain.
1689
1690       dcgettext(string [, domain [, category]])
1691              Return the translation of  string  in  text  domain  domain  for
1692              locale  category  category.  The default value for domain is the
1693              current value of TEXTDOMAIN.  The default value for category  is
1694              "LC_MESSAGES".
1695              If you supply a value for category, it must be a string equal to
1696              one of the known locale categories described in GAWK:  Effective
1697              AWK  Programming.   You  must  also  supply  a text domain.  Use
1698              TEXTDOMAIN if you want to use the current domain.
1699
1700       dcngettext(string1, string2, number [, domain [, category]])
1701              Return the plural form used for number  of  the  translation  of
1702              string1  and  string2  in text domain domain for locale category
1703              category.  The default value for domain is the current value  of
1704              TEXTDOMAIN.  The default value for category is "LC_MESSAGES".
1705              If you supply a value for category, it must be a string equal to
1706              one of the known locale categories described in GAWK:  Effective
1707              AWK  Programming.   You  must  also  supply  a text domain.  Use
1708              TEXTDOMAIN if you want to use the current domain.
1709

USER-DEFINED FUNCTIONS

1711       Functions in AWK are defined as follows:
1712
1713              function name(parameter list) { statements }
1714
1715       Functions execute when they  are  called  from  within  expressions  in
1716       either patterns or actions.  Actual parameters supplied in the function
1717       call are used to instantiate the  formal  parameters  declared  in  the
1718       function.   Arrays  are passed by reference, other variables are passed
1719       by value.
1720
1721       Since functions were not originally part of the AWK language, the  pro‐
1722       vision for local variables is rather clumsy: They are declared as extra
1723       parameters in the parameter list.  The convention is to separate  local
1724       variables  from  real parameters by extra spaces in the parameter list.
1725       For example:
1726
1727              function  f(p, q,     a, b)   # a and b are local
1728              {
1729                   ...
1730              }
1731
1732              /abc/     { ... ; f(1, 2) ; ... }
1733
1734       The left parenthesis in a function call is required to immediately fol‐
1735       low the function name, without any intervening whitespace.  This avoids
1736       a syntactic ambiguity with the concatenation operator.   This  restric‐
1737       tion does not apply to the built-in functions listed above.
1738
1739       Functions  may  call each other and may be recursive.  Function parame‐
1740       ters used as local variables are initialized to the null string and the
1741       number zero upon function invocation.
1742
1743       Use return expr to return a value from a function.  The return value is
1744       undefined if no value is provided, or if the function returns by “fall‐
1745       ing off” the end.
1746
1747       As  a  gawk  extension, functions may be called indirectly. To do this,
1748       assign the name of the function to be called, as a string, to  a  vari‐
1749       able.  Then use the variable as if it were the name of a function, pre‐
1750       fixed with an @ sign, like so:
1751              function myfunc()
1752              {
1753                   print "myfunc called"
1754                   ...
1755              }
1756
1757              {    ...
1758                   the_func = "myfunc"
1759                   @the_func()    # call through the_func to myfunc
1760                   ...
1761              }
1762       As of version 4.1.2, this works with user-defined  functions,  built-in
1763       functions, and extension functions.
1764
1765       If  --lint has been provided, gawk warns about calls to undefined func‐
1766       tions at parse time, instead of at  run  time.   Calling  an  undefined
1767       function at run time is a fatal error.
1768
1769       The word func may be used in place of function, although this is depre‐
1770       cated.
1771

DYNAMICALLY LOADING NEW FUNCTIONS

1773       You can dynamically add new built-in  functions  to  the  running  gawk
1774       interpreter  with the @load statement.  The full details are beyond the
1775       scope of this manual page; see GAWK: Effective AWK Programming.
1776

SIGNALS

1778       The gawk profiler accepts two signals.  SIGUSR1 causes  it  to  dump  a
1779       profile  and  function  call stack to the profile file, which is either
1780       awkprof.out, or whatever file was named with the --profile option.   It
1781       then  continues  to  run.   SIGHUP  causes gawk to dump the profile and
1782       function call stack and then exit.
1783

INTERNATIONALIZATION

1785       String constants are sequences of characters enclosed in double quotes.
1786       In non-English speaking environments, it is possible to mark strings in
1787       the AWK program as requiring translation to the local natural language.
1788       Such  strings  are  marked in the AWK program with a leading underscore
1789       (“_”).  For example,
1790
1791              gawk 'BEGIN { print "hello, world" }'
1792
1793       always prints hello, world.  But,
1794
1795              gawk 'BEGIN { print _"hello, world" }'
1796
1797       might print bonjour, monde in France.
1798
1799       There are several steps involved in producing and running a localizable
1800       AWK program.
1801
1802       1.  Add  a BEGIN action to assign a value to the TEXTDOMAIN variable to
1803           set the text domain to a name associated with your program:
1804
1805                BEGIN { TEXTDOMAIN = "myprog" }
1806
1807           This allows gawk to find the .gmo file associated  with  your  pro‐
1808           gram.  Without this step, gawk uses the messages text domain, which
1809           likely does not contain translations for your program.
1810
1811       2.  Mark all strings that should  be  translated  with  leading  under‐
1812           scores.
1813
1814       3.  If necessary, use the dcgettext() and/or bindtextdomain() functions
1815           in your program, as appropriate.
1816
1817       4.  Run gawk --gen-pot -f myprog.awk > myprog.pot to  generate  a  .pot
1818           file for your program.
1819
1820       5.  Provide  appropriate translations, and build and install the corre‐
1821           sponding .gmo files.
1822
1823       The internationalization features are described in full detail in GAWK:
1824       Effective AWK Programming.
1825

POSIX COMPATIBILITY

1827       A  primary  goal  for gawk is compatibility with the POSIX standard, as
1828       well as with the latest version of Brian Kernighan's awk.  To this end,
1829       gawk  incorporates  the  following  user visible features which are not
1830       described in the AWK book, but are part of the Brian  Kernighan's  ver‐
1831       sion of awk, and are in the POSIX standard.
1832
1833       The  book  indicates that command line variable assignment happens when
1834       awk would otherwise open the argument as a file,  which  is  after  the
1835       BEGIN rule is executed.  However, in earlier implementations, when such
1836       an assignment appeared before any file names, the assignment would hap‐
1837       pen before the BEGIN rule was run.  Applications came to depend on this
1838       “feature.”  When awk was changed to match  its  documentation,  the  -v
1839       option  for  assigning  variables before program execution was added to
1840       accommodate applications that depended upon the  old  behavior.   (This
1841       feature  was  agreed  upon  by  both  the Bell Laboratories and the GNU
1842       developers.)
1843
1844       When processing arguments, gawk uses the special option “--” to  signal
1845       the end of arguments.  In compatibility mode, it warns about but other‐
1846       wise ignores undefined options.  In normal  operation,  such  arguments
1847       are passed on to the AWK program for it to process.
1848
1849       The  AWK  book  does not define the return value of srand().  The POSIX
1850       standard has it return the seed it was using, to allow keeping track of
1851       random  number  sequences.   Therefore srand() in gawk also returns its
1852       current seed.
1853
1854       Other features are: The use of multiple -f options (from MKS awk);  the
1855       ENVIRON array; the \a, and \v escape sequences (done originally in gawk
1856       and fed back into the Bell Laboratories  version);  the  tolower()  and
1857       toupper()  built-in functions (from the Bell Laboratories version); and
1858       the ISO C conversion specifications in printf (done first in  the  Bell
1859       Laboratories version).
1860

HISTORICAL FEATURES

1862       There  is  one feature of historical AWK implementations that gawk sup‐
1863       ports: It is possible to call the length() built-in function  not  only
1864       with no argument, but even without parentheses!  Thus,
1865
1866              a = length     # Holy Algol 60, Batman!
1867
1868       is the same as either of
1869
1870              a = length()
1871              a = length($0)
1872
1873       Using  this  feature  is poor practice, and gawk issues a warning about
1874       its use if --lint is specified on the command line.
1875

GNU EXTENSIONS

1877       Gawk has a too-large number of  extensions  to  POSIX  awk.   They  are
1878       described  in  this  section.  All the extensions described here can be
1879       disabled by invoking gawk with the --traditional or --posix options.
1880
1881       The following features of gawk are not available in POSIX awk.
1882
1883       · No path search is performed  for  files  named  via  the  -f  option.
1884         Therefore the AWKPATH environment variable is not special.
1885
1886       · There is no facility for doing file inclusion (gawk's @include mecha‐
1887         nism).
1888
1889       · There is no facility for dynamically adding new functions written  in
1890         C (gawk's @load mechanism).
1891
1892       · The \x escape sequence.
1893
1894       · The ability to continue lines after ?  and :.
1895
1896       · Octal and hexadecimal constants in AWK programs.
1897
1898       · The  ARGIND, BINMODE, ERRNO, LINT, PREC, ROUNDMODE, RT and TEXTDOMAIN
1899         variables are not special.
1900
1901       · The IGNORECASE variable and its side-effects are not available.
1902
1903       · The FIELDWIDTHS variable and fixed-width field splitting.
1904
1905       · The FPAT variable and field splitting based on field values.
1906
1907       · The FUNCTAB, SYMTAB, and PROCINFO arrays are not available.
1908
1909       · The use of RS as a regular expression.
1910
1911       · The special file names available for I/O redirection are  not  recog‐
1912         nized.
1913
1914       · The |& operator for creating coprocesses.
1915
1916       · The BEGINFILE and ENDFILE special patterns are not available.
1917
1918       · The  ability to split out individual characters using the null string
1919         as the value of FS, and as the third argument to split().
1920
1921       · An optional fourth argument  to  split()  to  receive  the  separator
1922         texts.
1923
1924       · The optional second argument to the close() function.
1925
1926       · The optional third argument to the match() function.
1927
1928       · The ability to use positional specifiers with printf and sprintf().
1929
1930       · The ability to pass an array to length().
1931
1932       · The and(), asort(), asorti(), bindtextdomain(), compl(), dcgettext(),
1933         dcngettext(),  gensub(),  lshift(),   mktime(),   or(),   patsplit(),
1934         rshift(), strftime(), strtonum(), systime() and xor() functions.
1935
1936       · Localizable strings.
1937
1938       · Non-fatal I/O.
1939
1940       · Retryable I/O.
1941
1942       The  AWK book does not define the return value of the close() function.
1943       Gawk's close() returns the value from  fclose(3),  or  pclose(3),  when
1944       closing an output file or pipe, respectively.  It returns the process's
1945       exit status when closing an input pipe.  The return value is -1 if  the
1946       named file, pipe or coprocess was not opened with a redirection.
1947
1948       When  gawk is invoked with the --traditional option, if the fs argument
1949       to the -F option is “t”, then FS is set to  the  tab  character.   Note
1950       that  typing  gawk  -F\t ...  simply causes the shell to quote the “t,”
1951       and does not pass “\t” to the -F option.  Since this is a  rather  ugly
1952       special  case, it is not the default behavior.  This behavior also does
1953       not occur if --posix has been specified.  To really get a tab character
1954       as  the  field  separator, it is best to use single quotes: gawk -F'\t'
1955       ....
1956

ENVIRONMENT VARIABLES

1958       The AWKPATH environment variable can be  used  to  provide  a  list  of
1959       directories that gawk searches when looking for files named via the -f,
1960       --file, -i and --include options, and the @include directive.   If  the
1961       initial  search  fails, the path is searched again after appending .awk
1962       to the filename.
1963
1964       The AWKLIBPATH environment variable can be used to provide  a  list  of
1965       directories  that gawk searches when looking for files named via the -l
1966       and --load options.
1967
1968       The GAWK_READ_TIMEOUT environment variable can be  used  to  specify  a
1969       timeout in milliseconds for reading input from a terminal, pipe or two-
1970       way communication including sockets.
1971
1972       For connection to a remote host via socket, GAWK_SOCK_RETRIES  controls
1973       the  number  of  retries,  and GAWK_MSEC_SLEEP and the interval between
1974       retries.  The interval is in milliseconds. On systems that do not  sup‐
1975       port  usleep(3),  the value is rounded up to an integral number of sec‐
1976       onds.
1977
1978       If POSIXLY_CORRECT exists in the environment, then gawk behaves exactly
1979       as  if  --posix  had been specified on the command line.  If --lint has
1980       been specified, gawk issues a warning message to this effect.
1981

EXIT STATUS

1983       If the exit statement is used with a value, then gawk  exits  with  the
1984       numeric value given to it.
1985
1986       Otherwise,  if there were no problems during execution, gawk exits with
1987       the value of the C constant EXIT_SUCCESS.  This is usually zero.
1988
1989       If an error occurs, gawk  exits  with  the  value  of  the  C  constant
1990       EXIT_FAILURE.  This is usually one.
1991
1992       If  gawk exits because of a fatal error, the exit status is 2.  On non-
1993       POSIX systems, this value may be mapped to EXIT_FAILURE.
1994

VERSION INFORMATION

1996       This man page documents gawk, version 4.2.
1997

AUTHORS

1999       The original version of UNIX awk was designed and implemented by Alfred
2000       Aho, Peter Weinberger, and Brian Kernighan of Bell Laboratories.  Brian
2001       Kernighan continues to maintain and enhance it.
2002
2003       Paul Rubin and Jay Fenlason, of the  Free  Software  Foundation,  wrote
2004       gawk,  to be compatible with the original version of awk distributed in
2005       Seventh Edition UNIX.  John Woods contributed a number  of  bug  fixes.
2006       David  Trueman,  with contributions from Arnold Robbins, made gawk com‐
2007       patible with the new version of UNIX awk.  Arnold Robbins is  the  cur‐
2008       rent maintainer.
2009
2010       See GAWK: Effective AWK Programming for a full list of the contributors
2011       to gawk and its documentation.
2012
2013       See the README file in the gawk distribution for up-to-date information
2014       about maintainers and which ports are currently supported.
2015

BUG REPORTS

2017       If  you  find  a  bug  in  gawk,  please  send  electronic mail to bug-
2018       gawk@gnu.org.  Please include your operating system and  its  revision,
2019       the version of gawk (from gawk --version), which C compiler you used to
2020       compile it, and a test program and data that are as small  as  possible
2021       for reproducing the problem.
2022
2023       Before  sending  a  bug report, please do the following things.  First,
2024       verify that you have the latest version of gawk.   Many  bugs  (usually
2025       subtle  ones)  are  fixed at each release, and if yours is out of date,
2026       the problem may already have been solved.  Second, please see  if  set‐
2027       ting  the  environment  variable  LC_ALL  to  LC_ALL=C causes things to
2028       behave as you expect. If so, it's a locale issue, and may  or  may  not
2029       really  be a bug.  Finally, please read this man page and the reference
2030       manual carefully to be sure that what you think is  a  bug  really  is,
2031       instead of just a quirk in the language.
2032
2033       Whatever  you do, do NOT post a bug report in comp.lang.awk.  While the
2034       gawk developers occasionally read this newsgroup, posting  bug  reports
2035       there  is  an  unreliable  way to report bugs.  Instead, please use the
2036       electronic mail addresses given above.  Really.
2037
2038       If you're using a GNU/Linux or BSD-based system, you may wish to submit
2039       a  bug  report  to  the  vendor of your distribution.  That's fine, but
2040       please send a copy to the official email address as well, since there's
2041       no  guarantee  that  the bug report will be forwarded to the gawk main‐
2042       tainer.
2043

BUGS

2045       The -F option is not necessary given the command line variable  assign‐
2046       ment feature; it remains only for backwards compatibility.
2047

SEE ALSO

2049       egrep(1),   sed(1),   getpid(2),   getppid(2),  getpgrp(2),  getuid(2),
2050       geteuid(2),  getgid(2),  getegid(2),  getgroups(2),  printf(3),   strf‐
2051       time(3), usleep(3)
2052
2053       The  AWK Programming Language, Alfred V. Aho, Brian W. Kernighan, Peter
2054       J. Weinberger, Addison-Wesley, 1988.  ISBN 0-201-07981-X.
2055
2056       GAWK: Effective AWK Programming, Edition 4.2,  shipped  with  the  gawk
2057       source.   The  current  version of this document is available online at
2058       https://www.gnu.org/software/gawk/manual.
2059
2060       The    GNU    gettext    documentation,     available     online     at
2061       https://www.gnu.org/software/gettext.
2062

EXAMPLES

2064       Print and sort the login names of all users:
2065
2066            BEGIN     { FS = ":" }
2067                 { print $1 | "sort" }
2068
2069       Count lines in a file:
2070
2071                 { nlines++ }
2072            END  { print nlines }
2073
2074       Precede each line by its number in the file:
2075
2076            { print FNR, $0 }
2077
2078       Concatenate and line number (a variation on a theme):
2079
2080            { print NR, $0 }
2081
2082       Run an external command for particular lines of data:
2083
2084            tail -f access_log |
2085            awk '/myhome.html/ { system("nmap " $1 ">> logdir/myhome.html") }'
2086

ACKNOWLEDGEMENTS

2088       Brian  Kernighan provided valuable assistance during testing and debug‐
2089       ging.  We thank him.
2090

COPYING PERMISSIONS

2092       Copyright © 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2093       2001, 2002, 2003, 2004, 2005, 2007, 2009, 2010, 2011, 2012, 2013, 2014,
2094       2015, 2016, 2017, 2018 Free Software Foundation, Inc.
2095
2096       Permission is granted to make and distribute verbatim  copies  of  this
2097       manual  page  provided  the copyright notice and this permission notice
2098       are preserved on all copies.
2099
2100       Permission is granted to copy and distribute modified versions of  this
2101       manual  page  under  the conditions for verbatim copying, provided that
2102       the entire resulting derived work is distributed under the terms  of  a
2103       permission notice identical to this one.
2104
2105       Permission  is granted to copy and distribute translations of this man‐
2106       ual page into another language, under the above conditions for modified
2107       versions,  except that this permission notice may be stated in a trans‐
2108       lation approved by the Foundation.
2109
2110
2111
2112Free Software Foundation          Feb 15 2018                          GAWK(1)
Impressum