home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / compcomp / gawkos2 / gawk.man < prev    next >
Encoding:
Text File  |  1990-05-08  |  32.5 KB  |  893 lines

  1. NAME
  2.      gawk - pattern scanning and processing language
  3.  
  4. SYNOPSIS
  5.      gawk [ -a ] [ -e ] [ -c ] [ -C ] [ -V ] [ -Ffs ] [ -v
  6.      var=val ] -f program-file [ -- ] file ...
  7.      gawk [ -a ] [ -e ] [ -c ] [ -C ] [ -V ] [ -Ffs ] [ -v
  8.      var=val ] [ -- ] program-text file ...
  9.  
  10. DESCRIPTION
  11.      Gawk is the GNU Project's implementation of the AWK program-
  12.      ming language.  It conforms to the definition and descrip-
  13.      tion of the language in The AWK Programming Language, by
  14.      Aho, Kernighan, and Weinberger, with the additional features
  15.      defined in the System V Release 4 version of UNIX awk, and
  16.      some GNU-specific extensions.
  17.  
  18.      The command line consists of options to gawk itself, the AWK
  19.      program text (if not supplied via the -f option), and values
  20.      to be made available in the ARGC and ARGV pre-defined AWK
  21.      variables.
  22.  
  23.      Gawk accepts the following options, which should be avail-
  24.      able on any implementation of the AWK language.
  25.  
  26.      -Ffs Use fs for the input field separator (the value of the
  27.           FS predefined variable).
  28.  
  29.      -v var=val
  30.           Assign the value val, to the variable var, before exe-
  31.           cution of the program begins.  Such variable values are
  32.           available to the BEGIN block of an AWK program.
  33.  
  34.      -f program-file
  35.           Read the AWK program source from the file program-file,
  36.           instead of from the first command line argument.  Mul-
  37.           tiple -f options may be used.
  38.  
  39.      --   Signal the end of options. This is useful to allow
  40.           further arguments to the AWK program itself to start
  41.           with a ``-''.  This is mainly for consistency with the
  42.           argument parsing convention used by most other System V
  43.           programs.
  44.  
  45.      The following options are specific to the GNU implementa-
  46.      tion.
  47.  
  48.      -a   Use AWK style regular expressions as described in the
  49.           book.  This is the current default, but may not be when
  50.           the POSIX P1003.2 standard is finalized.  It is orthog-
  51.           onal to -c.
  52.  
  53.      -e   Use egrep(1) style regular expressions as described in
  54.           POSIX standard.  This may become the default when the
  55.           POSIX P1003.2 standard is finalized.  It is orthogonal
  56.           to -c.
  57.  
  58.      -c   Run in compatibility mode.  In compatibility mode, gawk
  59.           behaves identically to UNIX awk; none of the GNU-
  60.           specific extensions are recognized.
  61.  
  62.      -C   Print the short version of the GNU copyright informa-
  63.           tion message on the error output.  This option may
  64.           disappear in a future version of gawk.
  65.  
  66.      -V   Print version information for this particular copy of
  67.           gawk on the error output.  This is useful mainly for
  68.           knowing if the current copy of gawk on your system is
  69.           up to date with respect to whatever the Free Software
  70.           Foundation is distributing.  This option may disappear
  71.           in a future version of gawk.
  72.  
  73.      Any other options are flagged as illegal, but are otherwise
  74.      ignored.
  75.  
  76.      An AWK program consists of a sequence of pattern-action
  77.      statements and optional function definitions.
  78.  
  79.           pattern   { action statements }
  80.           function name(parameter list) { statements }
  81.  
  82.      Gawk first reads the program source from the program-file(s)
  83.      if specified, or from the first non-option argument on the
  84.      command line.  The -f option may be used multiple times on
  85.      the command line.  Gawk will read the program text as if all
  86.      the program-files had been concatenated together.  This is
  87.      useful for building libraries of AWK functions, without hav-
  88.      ing to include them in each new AWK program that uses them.
  89.      To use a library function in a file from a program typed in
  90.      on the command line, specify /dev/tty as one of the
  91.      program-files, type your program, and end it with a ^D
  92.      (control-d).
  93.  
  94.      The environment variable AWKPATH specifies a search path to
  95.      use when finding source files named with the -f option.  If
  96.      this variable does not exist, the default path is
  97.      ".:/usr/lib/awk:/usr/local/lib/awk".  If a file name given
  98.      to the -f option contains a ``/'' character, no path search
  99.      is performed.
  100.  
  101.      Gawk compiles the program into an internal form, executes
  102.      the code in the BEGIN block(s) (if any), and then proceeds
  103.      to read each file named in the ARGV array.  If there are no
  104.      files named on the command line, gawk reads the standard
  105.      input.
  106.  
  107.      If a ``file'' named on the command line has the form var=val
  108.      it is treated as a variable assignment. The variable var
  109.      will be assigned the value val.  This is most useful for
  110.      dynamically assigning values to the variables AWK uses to
  111.      control how input is broken into fields and records. It is
  112.      also useful for controlling state if multiple passes are
  113.      needed over a single data file.
  114.  
  115.      For each line in the input, gawk tests to see if it matches
  116.      any pattern in the AWK program.  For each pattern that the
  117.      line matches, the associated action is executed.
  118.  
  119. VARIABLES AND FIELDS
  120.      AWK variables are dynamic; they come into existence when
  121.      they are first used. Their values are either floating-point
  122.      numbers or strings, depending upon how they are used. AWK
  123.      also has one dimension arrays; multiply dimensioned arrays
  124.      may be simulated.  There are several pre-defined variables
  125.      that AWK sets as a program runs; these will be described as
  126.      needed and summarized below.
  127.  
  128.      Fields
  129.  
  130.      As each input line is read, gawk splits the line into
  131.      fields, using the value of the FS variable as the field
  132.      separator.  If FS is a single character, fields are
  133.      separated by that character.  Otherwise, FS is expected to
  134.      be a full regular expression.  In the special case that FS
  135.      is a single blank, fields are separated by runs of blanks
  136.      and/or tabs.  Note that the value of IGNORECASE (see below)
  137.      will also affect how fields are split when FS is a regular
  138.      expression.
  139.  
  140.      Each field in the input line may be referenced by its posi-
  141.      tion, $1, $2, and so on.  $0 is the whole line. The value of
  142.      a field may be assigned to as well.  Fields need not be
  143.      referenced by constants:
  144.  
  145.           n = 5
  146.           print $n
  147.  
  148.      prints the fifth field in the input line.  The variable NF
  149.      is set to the total number of fields in the input line.
  150.  
  151.      References to non-existent fields (i.e. fields after $NF),
  152.      produce the null-string. However, assigning to a non-
  153.      existent field (e.g., $(NF+2) = 5) will increase the value
  154.      of NF, create any intervening fields with the null string as
  155.      their value, and cause the value of $0 to be recomputed,
  156.      with the fields being separated by the value of OFS.
  157.  
  158.      Built-in Variables
  159.  
  160.      AWK's built-in variables are:
  161.  
  162.           ARGC
  163.             the number of command line arguments (does not
  164.             include options to gawk, or the program source).
  165.  
  166.           ARGV
  167.             array of command line arguments. The array is indexed
  168.             from 0 to ARGC - 1.  Dynamically changing the con-
  169.             tents of ARGV can control the files used for data.
  170.  
  171.           ENVIRON
  172.             An array containing the values of the current
  173.             environment.  The array is indexed by the environment
  174.             variables, each element being the value of that vari-
  175.             able (e.g., ENVIRON["HOME"] might be /u/arnold).
  176.             Changing this array does not affect the environment
  177.             seen by programs which gawk spawns via redirection or
  178.             the system function.  (This may change in a future
  179.             version of gawk.)
  180.  
  181.           FILENAME
  182.             the name of the current input file.  If no files are
  183.             specified on the command line, the value of FILENAME
  184.             is ``-''.
  185.  
  186.           FNR
  187.             the input record number in the current input file.
  188.  
  189.           FSthe input field separator, a blank by default.
  190.  
  191.           IGNORECASE
  192.             Controls the case-sensitivity of all regular expres-
  193.             sion operations. If IGNORECASE has a non-zero value,
  194.             then pattern matching in rules, field splitting with
  195.             FS, regular expression matching with ~ and !~, and
  196.             the gsub(), index(), match(), split(), and sub()
  197.             pre-defined functions will all ignore case when doing
  198.             regular expression operations.  Thus, if IGNORECASE
  199.             is not equal to zero, /aB/ matches all of the strings
  200.             "ab", "aB", "Ab", and "AB".  As with all AWK vari-
  201.             ables, the initial value of IGNORECASE is zero, so
  202.             all regular expression operations are normally case-
  203.             sensitive.
  204.  
  205.           NFthe number of fields in the current input record.
  206.  
  207.           NRthe total number of input records seen so far.
  208.  
  209.           OFMT
  210.             the output format for numbers, %.6g by default.
  211.  
  212.           OFS
  213.             the output field separator, a blank by default.
  214.  
  215.           ORS
  216.             the output record separator, by default a newline.
  217.  
  218.           RSthe input record separator, by default a newline.  RS
  219.             is exceptional in that only the first character of
  220.             its string value is used for separating records. If
  221.             RS is set to the null string, then records are
  222.             separated by blank lines.  When RS is set to the null
  223.             string, then the newline character always acts as a
  224.             field separator, in addition to whatever value FS may
  225.             have.
  226.  
  227.           RSTART
  228.             the index of the first character matched by match();
  229.             0 if no match.
  230.  
  231.           RLENGTH
  232.             the length of the string matched by match(); -1 if no
  233.             match.
  234.  
  235.           SUBSEP
  236.             the character used to separate multiple subscripts in
  237.             array elements, by default "\034".
  238.  
  239.      Arrays
  240.  
  241.      Arrays are subscripted with an expression between square
  242.      brackets ([ and ]).  If the expression is an expression list
  243.      (expr, expr ...) then the array subscript is a string con-
  244.      sisting of the concatenation of the (string) value of each
  245.      expression, separated by the value of the SUBSEP variable.
  246.      This facility is used to simulate multiply dimensioned
  247.      arrays. For example:
  248.  
  249.           i = "A" ; j = "B" ; k = "C"
  250.           x[i, j, k] = "hello, world\n"
  251.  
  252.      assigns the string "hello, world\n" to the element of the
  253.      array x which is indexed by the string "A\034B\034C". All
  254.      arrays in AWK are associative, i.e. indexed by string
  255.      values.
  256.  
  257.      The special operator in may be used in an if or while state-
  258.      ment to see if an array has an index consisting of a partic-
  259.      ular value.
  260.  
  261.           if (val in array)
  262.                print array[val]
  263.  
  264.      If the array has multiple subscripts, use (i, j) in array.
  265.  
  266.      The in construct may also be used in a for loop to iterate
  267.      over all the elements of an array.
  268.  
  269.      An element may be deleted from an array using the delete
  270.      statement.
  271.  
  272.      Variable Typing
  273.  
  274.      Variables and fields may be (floating point) numbers, or
  275.      strings, or both. How the value of a variable is interpreted
  276.      depends upon its context. If used in a numeric expression,
  277.      it will be treated as a number, if used as a string it will
  278.      be treated as a string.
  279.  
  280.      To force a variable to be treated as a number, add 0 to it;
  281.      to force it to be treated as a string, concatenate it with
  282.      the null string.
  283.  
  284.      The AWK language defines comparisons as being done numeri-
  285.      cally if possible, otherwise one or both operands are con-
  286.      verted to strings and a string comparison is performed.
  287.  
  288.      Uninitialized variables have the numeric value 0 and the
  289.      string value "" (the null, or empty, string).
  290.  
  291. PATTERNS AND ACTIONS
  292.      AWK is a line oriented language. The pattern comes first,
  293.      and then the action. Action statements are enclosed in { and
  294.      }.  Either the pattern may be missing, or the action may be
  295.      missing, but, of course, not both. If the pattern is miss-
  296.      ing, the action will be executed for every single line of
  297.      input.  A missing action is equivalent to
  298.  
  299.           { print }
  300.  
  301.      which prints the entire line.
  302.  
  303.      Comments begin with the ``#'' character, and continue until
  304.      the end of the line.  Blank lines may be used to separate
  305.      statements.  Normally, a statement ends with a newline, how-
  306.      ever, this is not the case for lines ending in a ``,'',
  307.      ``{'', ``?'', ``:'', ``&&'', or ``||''.  Lines ending in do
  308.      or else also have their statements automatically continued
  309.      on the following line.  In other cases, a line can be con-
  310.      tinued by ending it with a ``\'', in which case the newline
  311.      will be ignored.
  312.  
  313.      Multiple statements may be put on one line by separating
  314.      them with a ``;''.  This applies to both the statements
  315.      within the action part of a pattern-action pair (the usual
  316.      case), and to the pattern-action statements themselves.
  317.  
  318.      Patterns
  319.      AWK patterns may be one of the following:
  320.  
  321.           BEGIN
  322.           END
  323.           /regular expression/
  324.           relational expression
  325.           pattern && pattern
  326.           pattern || pattern
  327.           pattern ? pattern : pattern
  328.           (pattern)
  329.           ! pattern
  330.           pattern1, pattern2
  331.  
  332.      BEGIN and END are two special kinds of patterns which are
  333.      not tested against the input.  The action parts of all BEGIN
  334.      patterns are merged as if all the statements had been writ-
  335.      ten in a single BEGIN block. They are executed before any of
  336.      the input is read. Similarly, all the END blocks are merged,
  337.      and executed when all the input is exhausted (or when an
  338.      exit statement is executed).  BEGIN and END patterns cannot
  339.      be combined with other patterns in pattern expressions.
  340.      BEGIN and END patterns cannot have missing action parts.
  341.  
  342.      For /regular expression/ patterns, the associated statement
  343.      is executed for each input line that matches the regular
  344.      expression.  Regular expressions are the same as those in
  345.      egrep(1), and are summarized below.
  346.  
  347.      A relational expression may use any of the operators defined
  348.      below in the section on actions.  These generally test
  349.      whether certain fields match certain regular expressions.
  350.  
  351.      The &&, ||, and ! operators are logical AND, logical OR, and
  352.      logical NOT, respectively, as in C.  They do short-circuit
  353.      evaluation, also as in C, and are used for combining more
  354.      primitive pattern expressions. As in most languages,
  355.      parentheses may be used to change the order of evaluation.
  356.  
  357.      The ?: operator is like the same operator in C. If the first
  358.      pattern is true then the pattern used for testing is the
  359.      second pattern, otherwise it is the third. Only one of the
  360.      second and third patterns is evaluated.
  361.  
  362.      The pattern1, pattern2 form of an expression is called a
  363.      range pattern.  It matches all input lines starting with a
  364.      line that matches pattern1, and continuing until a line that
  365.      matches pattern2, inclusive. It does not combine with any
  366.      other sort of pattern expression.
  367.  
  368.      Regular Expressions
  369.      Regular expressions are the extended kind found in egrep.
  370.      They are composed of characters as follows:
  371.  
  372.           c matches the non-metacharacter c.
  373.  
  374.           \cmatches the literal character c.
  375.  
  376.           . matches any character except newline.
  377.  
  378.           ^ matches the beginning of a line or a string.
  379.  
  380.           $ matches the end of a line or a string.
  381.  
  382.           [abc...]
  383.             character class, matches any of the characters
  384.             abc....
  385.  
  386.           [^abc...]
  387.             negated character class, matches any character except
  388.             abc... and newline.
  389.  
  390.           r1|r2
  391.             alternation: matches either r1 or r2.
  392.  
  393.           r1r2
  394.             concatenation: matches r1, and then r2.
  395.  
  396.           r+matches one or more r's.
  397.  
  398.           r*matches zero or more r's.
  399.  
  400.           r?matches zero or one r's.
  401.  
  402.           (r)
  403.             grouping: matches r.
  404.      The escape sequences that are valid in string constants (see
  405.      below) are also legal in regular expressions.
  406.  
  407.      Actions
  408.      Action statements are enclosed in braces, { and }.  Action
  409.      statements consist of the usual assignment, conditional, and
  410.      looping statements found in most languages. The operators,
  411.      control statements, and input/output statements available
  412.      are patterned after those in C.
  413.  
  414.      Operators
  415.  
  416.      The operators in AWK, in order of increasing precedence, are
  417.  
  418.           = += -= *= /= %= ^=
  419.             Assignment. Both absolute assignment (var = value)
  420.             and operator-assignment (the other forms) are sup-
  421.             ported.
  422.  
  423.           ?:The C conditional expression. This has the form expr1
  424.             ? expr2 : expr3. If expr1 is true, the value of the
  425.             expression is expr2, otherwise it is expr3.  Only one
  426.             of expr2 and expr3 is evaluated.
  427.  
  428.           ||logical OR.
  429.  
  430.           &&logical AND.
  431.  
  432.           ~ !~
  433.             regular expression match, negated match.
  434.  
  435.           < <= > >= != ==
  436.             the regular relational operators.
  437.  
  438.           blank
  439.             string concatenation.
  440.  
  441.           + -
  442.             addition and subtraction.
  443.  
  444.           * / %
  445.             multiplication, division, and modulus.
  446.  
  447.           + - !
  448.             unary plus, unary minus, and logical negation.
  449.  
  450.           ^ exponentiation (** may also be used, and **= for the
  451.             assignment operator).
  452.  
  453.           ++ --
  454.             increment and decrement, both prefix and postfix.
  455.  
  456.           $ field reference.
  457.  
  458.      Control Statements
  459.  
  460.      The control statements are as follows:
  461.  
  462.           if (condition) statement [ else statement ]
  463.           while (condition) statement
  464.           do statement while (condition)
  465.           for (expr1; expr2; expr3) statement
  466.           for (var in array) statement
  467.           break
  468.           continue
  469.           delete array[index]
  470.           exit [ expression ]
  471.           { statements }
  472.  
  473.      I/O Statements
  474.  
  475.      The input/output statements are as follows:
  476.  
  477.           close(filename)
  478.             close file (or pipe, see below).
  479.  
  480.           getline
  481.             set $0 from next input record; set NF, NR, FNR.
  482.  
  483.           getline <file
  484.             set $0 from next record of file; set NF.
  485.  
  486.           getline var
  487.             set var from next input record; set NF, FNR.
  488.  
  489.           getline var <file
  490.             set var from next record of file.
  491.  
  492.           next
  493.             Stop processing the current input record. The next
  494.             input record is read and processing starts over with
  495.             the first pattern in the AWK program. If the end of
  496.             the input data is reached, the END block(s), if any,
  497.             are executed.
  498.  
  499.           print
  500.             prints the current record.
  501.  
  502.           print expr-list
  503.             prints expressions.
  504.  
  505.           print expr-list >file
  506.             prints expressions on file.
  507.  
  508.           printf fmt, expr-list
  509.             format and print.
  510.  
  511.           printf fmt, expr-list >file
  512.             format and print on file.
  513.  
  514.           system(cmd-line)
  515.             execute the command cmd-line, and return the exit
  516.             status.  (This may not be available on systems
  517.             besides UNIX and GNU.)
  518.  
  519.      Other input/output redirections are also allowed. For print
  520.      and printf, >>file appends output to the file, while |
  521.      command writes on a pipe.  In a similar fashion, command |
  522.      getline pipes into getline.  Getline will return 0 on end of
  523.      file, and -1 on an error.
  524.  
  525.      The printf Statement
  526.  
  527.      The AWK versions of the printf and sprintf (see below) func-
  528.      tions accept the following conversion specification formats:
  529.  
  530.           %cAn ASCII character.  If the argument used for %c is
  531.             numeric, it is treated as a character and printed.
  532.             Otherwise, the argument is assumed to be a string,
  533.             and the only first character of that string is
  534.             printed.
  535.  
  536.           %dA decimal number (the integer part).
  537.  
  538.           %iJust like %d.
  539.  
  540.           %eA floating point number of the form
  541.             [-]d.ddddddE[+-]dd.
  542.  
  543.           %fA floating point number of the form [-]ddd.dddddd.
  544.  
  545.           %gUse e or f conversion, whichever is shorter, with
  546.             nonsignificant zeros suppressed.
  547.  
  548.           %oAn unsigned octal number (again, an integer).
  549.  
  550.           %sA character string.
  551.  
  552.           %xAn unsigned hexadecimal number (an integer).
  553.  
  554.           %XLike %x, but using ABCDEF instead of abcdef.
  555.  
  556.           %%A single % character; no argument is converted.
  557.  
  558.      There are optional, additional parameters that may lie
  559.      between the % and the control letter:
  560.  
  561.           - The expression should be left-justified within its
  562.             field.
  563.  
  564.           width
  565.             The field should be padded to this width. If the
  566.             number has a leading zero, then the field will be
  567.             padded with zeros.  Otherwise it is padded with
  568.             blanks.
  569.  
  570.           .prec
  571.             A number indicating the maximum width of strings or
  572.             digits to the right of the decimal point.
  573.  
  574.      The dynamic width and prec capabilities of the C library
  575.      printf routines are not supported.  However, they may be
  576.      simulated by using the AWK concatenation operation to build
  577.      up a format specification dynamically.
  578.  
  579.      Special File Names
  580.  
  581.      When doing I/O redirection from either print or printf into
  582.      a file, or via getline from a file, gawk recognizes certain
  583.      special filenames internally.  These filenames allow access
  584.      to open file descriptors inherited from gawk's parent pro-
  585.      cess (usually the shell).  The filenames are:
  586.  
  587.           /dev/stdin
  588.             The standard input.
  589.  
  590.           /dev/stdout
  591.             The standard output.
  592.  
  593.           /dev/stderr
  594.             The standard error output.
  595.  
  596.           /dev/fd/n
  597.             The file denoted by the open file descriptor n.
  598.  
  599.      These are particularly useful for error messages. For exam-
  600.      ple:
  601.  
  602.           print "You blew it!" > "/dev/stderr"
  603.  
  604.      whereas you would otherwise have to use
  605.  
  606.           print "You blew it!" | "cat 1>&2"
  607.  
  608.      These file names may also be used on the command line to
  609.      name data files.
  610.  
  611.      Numeric Functions
  612.  
  613.      AWK has the following pre-defined arithmetic functions:
  614.  
  615.           atan2(y, x)
  616.             returns the arctangent of y/x in radians.
  617.  
  618.           cos(expr)
  619.             returns the cosine in radians.
  620.  
  621.           exp(expr)
  622.             the exponential function.
  623.  
  624.           int(expr)
  625.             truncates to integer.
  626.  
  627.           log(expr)
  628.             the natural logarithm function.
  629.  
  630.           rand()
  631.             returns a random number between 0 and 1.
  632.  
  633.           sin(expr)
  634.             returns the sine in radians.
  635.  
  636.           sqrt(expr)
  637.             the square root function.
  638.  
  639.           srand(expr)
  640.             use expr as a new seed for the random number genera-
  641.             tor. If no expr is provided, the time of day will be
  642.             used.  The return value is the previous seed for the
  643.             random number generator.
  644.  
  645.      String Functions
  646.  
  647.      AWK has the following pre-defined string functions:
  648.  
  649.           gsub(r, s, t)
  650.             for each substring matching the regular expression r
  651.             in the string t, substitute the string s, and return
  652.             the number of substitutions.  If t is not supplied,
  653.             use $0.
  654.  
  655.           index(s, t)
  656.             returns the index of the string t in the string s, or
  657.             0 if t is not present.
  658.  
  659.           length(s)
  660.             returns the length of the string s.
  661.  
  662.           match(s, r)
  663.             returns the position in s where the regular expres-
  664.             sion r occurs, or 0 if r is not present, and sets the
  665.             values of RSTART and RLENGTH.
  666.  
  667.           split(s, a, r)
  668.             splits the string s into the array a on the regular
  669.             expression r, and returns the number of fields. If r
  670.             is omitted, FS is used instead.
  671.  
  672.           sprintf(fmt, expr-list)
  673.             prints expr-list according to fmt, and returns the
  674.             resulting string.
  675.  
  676.           sub(r, s, t)
  677.             this is just like gsub, but only the first matching
  678.             substring is replaced.
  679.  
  680.           substr(s, i, n)
  681.             returns the n-character substring of s starting at i.
  682.             If n is omitted, the rest of s is used.
  683.  
  684.           tolower(str)
  685.             returns a copy of the string str, with all the
  686.             upper-case characters in str translated to their
  687.             corresponding lower-case counterparts.  Non-
  688.             alphabetic characters are left unchanged.
  689.  
  690.           toupper(str)
  691.             returns a copy of the string str, with all the
  692.             lower-case characters in str translated to their
  693.             corresponding upper-case counterparts.  Non-
  694.             alphabetic characters are left unchanged.
  695.  
  696.      String Constants
  697.  
  698.      String constants in AWK are sequences of characters enclosed
  699.      between double quotes ("). Within strings, certain escape
  700.      sequences are recognized, as in C. These are:
  701.  
  702.           \\A literal backslash.
  703.  
  704.           \aThe ``alert'' character; usually the ASCII BEL char-
  705.             acter.
  706.  
  707.           \bbackspace.
  708.  
  709.           \fform-feed.
  710.  
  711.           \nnew line.
  712.  
  713.           \rcarriage return.
  714.  
  715.           \thorizontal tab.
  716.  
  717.           \vvertical tab.
  718.  
  719.           \xhex digits
  720.             The character represented by the string of hexade-
  721.             cimal digits following the \x.  As in ANSI C, all
  722.             following hexadecimal digits are considered part of
  723.             the escape sequence.  (This feature should tell us
  724.             something about language design by committee.) E.g.,
  725.             "\x1B" is the ASCII ESC (escape) character.
  726.  
  727.           \ddd
  728.             The character represented by the 1-, 2-, or 3-digit
  729.             sequence of octal digits. E.g. "\033" is the ASCII
  730.             ESC (escape) character.
  731.  
  732.           \cThe literal character c.
  733.  
  734.      The escape sequences may also be used inside constant regu-
  735.      lar expressions (e.g., /[ \t\f\n\r\v]/ matches whitespace
  736.      characters).
  737.  
  738. FUNCTIONS
  739.      Functions in AWK are defined as follows:
  740.  
  741.           function name(parameter list) { statements }
  742.  
  743.      Functions are executed when called from within the action
  744.      parts of regular pattern-action statements. Actual parame-
  745.      ters supplied in the function call are used to instantiate
  746.      the formal parameters declared in the function.  Arrays are
  747.      passed by reference, other variables are passed by value.
  748.  
  749.      Since functions were not originally part of the AWK
  750.      language, the provision for local variables is rather
  751.      clumsy: they are declared as extra parameters in the parame-
  752.      ter list. The convention is to separate local variables from
  753.      real parameters by extra spaces in the parameter list. For
  754.      example:
  755.  
  756.           function  f(p, q,     a, b) { # a & b are local
  757.                          ..... }
  758.  
  759.           /abc/     { ... ; f(1, 2) ; ... }
  760.  
  761.      The left parenthesis in a function call is required to
  762.      immediately follow the function name, without any interven-
  763.      ing white space.  This is to avoid a syntactic ambiguity
  764.      with the concatenation operator.  This restriction does not
  765.      apply to the built-in functions listed above.
  766.  
  767.      Functions may call each other and may be recursive.  Func-
  768.      tion parameters used as local variables are initialized to
  769.      the null string and the number zero upon function invoca-
  770.      tion.
  771.  
  772.      The word func may be used in place of function.
  773.  
  774. EXAMPLES
  775.      Print and sort the login names of all users:
  776.  
  777.           BEGIN     { FS = ":" }
  778.                { print $1 | "sort" }
  779.  
  780.      Count lines in a file:
  781.  
  782.                { nlines++ }
  783.           END  { print nlines }
  784.  
  785.      Precede each line by its number in the file:
  786.  
  787.           { print FNR, $0 }
  788.  
  789.      Concatenate and line number (a variation on a theme):
  790.  
  791.           { print NR, $0 }
  792.  
  793. SEE ALSO
  794.      egrep(1)
  795.  
  796.      The AWK Programming Language, Alfred V. Aho, Brian W. Ker-
  797.      nighan, Peter J. Weinberger, Addison-Wesley, 1988. ISBN 0-
  798.      201-07981-X.
  799.  
  800.      The GAWK Manual, published by the Free Software Foundation,
  801.      1989.
  802.  
  803. SYSTEM V RELEASE 4 COMPATIBILITY
  804.      A primary goal for gawk is compatibility with the latest
  805.      version of UNIX awk.  To this end, gawk incorporates the
  806.      following user visible features which are not described in
  807.      the AWK book, but are part of awk in System V Release 4.
  808.  
  809.      The -v option for assigning variables before program execu-
  810.      tion starts is new.  The book indicates that command line
  811.      variable assignment happens when awk would otherwise open
  812.      the argument as a file, which is after the BEGIN block is
  813.      executed.  However, in earlier implementations, when such an
  814.      assignment appeared before any file names, the assignment
  815.      would happen before the BEGIN block was run.  Applications
  816.      came to depend on this ``feature.'' When awk was changed to
  817.      match its documentation, this option was added to accomodate
  818.      applications that depended upon the old behaviour.
  819.  
  820.      When processing arguments, gawk uses the special option
  821.      ``--'' to signal the end of arguments, and warns about, but
  822.      otherwise ignores, undefined options.
  823.  
  824.      The AWK book does not define the return value of srand().
  825.      The System V Release 4 version of UNIX awk has it return the
  826.      seed it was using, to allow keeping track of random number
  827.      sequences. Therefore srand() in gawk also returns its
  828.      current seed.
  829.  
  830.      Other new features are: The use of multiple -f options; the
  831.      ENVIRON array; the \a, and \v, \x escape sequences; the
  832.      tolower and toupper built-in functions; and the ANSI C
  833.      conversion specifications in printf.
  834.  
  835. GNU EXTENSIONS
  836.      Gawk has some extensions to System V awk.  They are
  837.      described in this section.  All the extensions described
  838.      here can be disabled by compiling gawk with -DSTRICT, or by
  839.      invoking gawk with the -c option.  If the underlying operat-
  840.      ing system supports the /dev/fd directory and corresponding
  841.      files, then gawk can be compiled with -DNO_DEV_FD to disable
  842.      the special filename processing.
  843.  
  844.      The following features of gawk are not available in System V
  845.      awk.
  846.  
  847.           + The special file names available for I/O redirection
  848.             are not recognized.
  849.  
  850.           + The IGNORECASE variable and its side-effects are not
  851.             available.
  852.  
  853.           + No path search is performed for files named via the
  854.             -f option.  Therefore the AWKPATH environment vari-
  855.             able is not special.
  856.  
  857.           + The -a, -e, -c, -C, and -V command line options.
  858.  
  859.      The AWK book does not define the return value of the close
  860.      function.  Gawk's close returns the value from fclose(3), or
  861.      pclose(3), when closing a file or pipe, respectively.
  862.  
  863.      When gawk is invoked with the -c option, if the fs argument
  864.      to the -F option is ``t'', then FS will be set to the tab
  865.      character.  Since this is a rather ugly special case, it is
  866.      not the default behavior.
  867.  
  868. BUGS
  869.      The -F option is not necessary given the command line vari-
  870.      able assignment feature; it remains only for backwards com-
  871.      patibility.
  872.  
  873.      There are now too many options.  Fortunately, most of them
  874.      are rarely needed.
  875.  
  876. AUTHORS
  877.      The original version of UNIX awk was designed and imple-
  878.      mented by Alfred Aho, Peter Weinberger, and Brian Kernighan
  879.      of AT&T Bell Labs. Brian Kernighan continues to maintain and
  880.      enhance it.
  881.  
  882.      Paul Rubin and Jay Fenlason, of the Free Software Founda-
  883.      tion, wrote gawk, to be compatible with the original version
  884.      of awk distributed in Seventh Edition UNIX.  John Woods con-
  885.      tributed a number of bug fixes.  David Trueman of Dalhousie
  886.      University, with contributions from Arnold Robbins at Emory
  887.      University, made gawk compatible with the new version of
  888.      UNIX awk.
  889.  
  890. ACKNOWLEDGEMENTS
  891.      Brian Kernighan of Bell Labs provided valuable assistance
  892.      during testing and debugging.  We thank him.
  893.