home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gawk-doc-2.15 / gawk.1.pr next >
Encoding:
Text File  |  1993-05-19  |  49.0 KB  |  1,386 lines

  1.  
  2.  
  3.  
  4. GAWK(1)                 Utility Commands                  GAWK(1)
  5.  
  6.  
  7.  
  8. NAME
  9.      gawk - pattern scanning and processing language
  10.  
  11. SYNOPSIS
  12.      gawk [ POSIX or GNU style options ] -f _p_r_o_g_r_a_m-_f_i_l_e [  --  ]
  13.      file ...
  14.      gawk [ POSIX or GNU style options ] [ -- ] _p_r_o_g_r_a_m-_t_e_x_t file
  15.      ...
  16.  
  17. DESCRIPTION
  18.      _G_a_w_k is the GNU Project's implementation of the AWK program-
  19.      ming  language.   It  conforms  to  the  definition  of  the
  20.      language in the POSIX 1003.2 Command Language And  Utilities
  21.      Standard.   This version in turn is based on the description
  22.      in _T_h_e _A_W_K _P_r_o_g_r_a_m_m_i_n_g  _L_a_n_g_u_a_g_e,  by  Aho,  Kernighan,  and
  23.      Weinberger, with the additional features defined in the Sys-
  24.      tem V Release 4 version of UNIX  _a_w_k.   _G_a_w_k  also  provides
  25.      some GNU-specific extensions.
  26.  
  27.      The command line consists of options to _g_a_w_k itself, the AWK
  28.      program text (if not supplied via the -f or --file options),
  29.      and values to be made available in the ARGC  and  ARGV  pre-
  30.      defined AWK variables.
  31.  
  32. OPTIONS
  33.      _G_a_w_k options may be either the traditional POSIX one  letter
  34.      options, or the GNU style long options.  POSIX style options
  35.      start with a single ``-'', while GNU long options start with
  36.      ``--''.   GNU  style long options are provided for both GNU-
  37.      specific features and for POSIX  mandated  features.   Other
  38.      implementations  of  the  AWK  language  are  likely to only
  39.      accept the traditional one letter options.
  40.  
  41.      Following the POSIX standard, _g_a_w_k-specific options are sup-
  42.      plied  via  arguments to the -W option.  Multiple -W options
  43.      may be supplied,  or  multiple  arguments  may  be  supplied
  44.      together  if  they  are  separated by commas, or enclosed in
  45.      quotes and separated by white space.   Case  is  ignored  in
  46.      arguments   to   the  -W  option.   Each  -W  option  has  a
  47.      corresponding GNU style long option, as detailed below.
  48.  
  49.      _G_a_w_k accepts the following options.
  50.  
  51.      -F _f_s
  52.      --field-separator=_f_s
  53.           Use _f_s for the input field separator (the value of  the
  54.           FS predefined variable).
  55.  
  56.      -v _v_a_r=_v_a_l
  57.      --assign=_v_a_r=_v_a_l
  58.           Assign the value _v_a_l, to the variable _v_a_r, before  exe-
  59.           cution of the program begins.  Such variable values are
  60.  
  61.  
  62.  
  63. Free Software FoundationLast change: Apr 15 1993                   1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. GAWK(1)                 Utility Commands                  GAWK(1)
  71.  
  72.  
  73.  
  74.           available to the BEGIN block of an AWK program.
  75.  
  76.      -f _p_r_o_g_r_a_m-_f_i_l_e
  77.      --file=_p_r_o_g_r_a_m-_f_i_l_e
  78.           Read the AWK program source from the file _p_r_o_g_r_a_m-_f_i_l_e,
  79.           instead  of from the first command line argument.  Mul-
  80.           tiple -f (or --file) options may be used.
  81.  
  82.      -W compat
  83.      --compat    Run in  _c_o_m_p_a_t_i_b_i_l_i_t_y  mode.   In  compatibility
  84.                  mode, _g_a_w_k behaves identically to UNIX _a_w_k; none
  85.                  of the GNU-specific extensions  are  recognized.
  86.                  See GNU EXTENSIONS, below, for more information.
  87.  
  88.      -W copyleft
  89.      -W copyright
  90.      --copyleft
  91.      --copyright Print the short version  of  the  GNU  copyright
  92.                  information message on the error output.
  93.  
  94.      -W help
  95.      -W usage
  96.      --help
  97.      --usage     Print a relatively short summary of  the  avail-
  98.                  able options on the error output.
  99.  
  100.      -W lint
  101.      --lint      Provide warnings about constructs that are dubi-
  102.                  ous  or  non-portable  to  other AWK implementa-
  103.                  tions.
  104.      -W posix
  105.      --posix     This turns on _c_o_m_p_a_t_i_b_i_l_i_t_y mode, with the  fol-
  106.                  lowing additional restrictions:
  107.  
  108.                  o+ \x escape sequences are not recognized.
  109.  
  110.                  o+ The synonym func for the keyword  function  is
  111.                    not recognized.
  112.  
  113.                  o+ The operators ** and **=  cannot  be  used  in
  114.                    place of ^ and ^=.
  115.  
  116.      -W source=_p_r_o_g_r_a_m-_t_e_x_t
  117.      --source=_p_r_o_g_r_a_m-_t_e_x_t
  118.                  Use _p_r_o_g_r_a_m-_t_e_x_t as  AWK  program  source  code.
  119.                  This  option  allows  the  easy  intermixing  of
  120.                  library functions (used via the  -f  and  --file
  121.                  options) with source code entered on the command
  122.                  line.  It is intended primarily  for  medium  to
  123.                  large size AWK programs used in shell scripts.
  124.                  The -W source= form of this option uses the rest
  125.                  of  the  command line argument for _p_r_o_g_r_a_m-_t_e_x_t;
  126.  
  127.  
  128.  
  129. Free Software FoundationLast change: Apr 15 1993                   2
  130.  
  131.  
  132.  
  133.  
  134. GAWK(1)                 Utility Commands                  GAWK(1)
  135.  
  136.  
  137.  
  138.                  no other options to -W will be recognized in the
  139.                  same argument.
  140.  
  141.      -W version
  142.      --version   Print version information  for  this  particular
  143.                  copy  of _g_a_w_k on the error output.  This is use-
  144.                  ful mainly for knowing if the  current  copy  of
  145.                  _g_a_w_k  on  your system is up to date with respect
  146.                  to whatever the Free Software Foundation is dis-
  147.                  tributing.
  148.  
  149.      --          Signal the end of options.  This  is  useful  to
  150.                  allow  further  arguments  to  the  AWK  program
  151.                  itself to start with a ``-''.   This  is  mainly
  152.                  for  consistency  with the argument parsing con-
  153.                  vention used by most other POSIX programs.
  154.  
  155.      Any other options are flagged as illegal, but are  otherwise
  156.      ignored.
  157.  
  158. AWK PROGRAM EXECUTION
  159.      An AWK program consists  of  a  sequence  of  pattern-action
  160.      statements and optional function definitions.
  161.  
  162.           _p_a_t_t_e_r_n   { _a_c_t_i_o_n _s_t_a_t_e_m_e_n_t_s }
  163.           function _n_a_m_e(_p_a_r_a_m_e_t_e_r _l_i_s_t) { _s_t_a_t_e_m_e_n_t_s }
  164.  
  165.      _G_a_w_k first reads the program source from the _p_r_o_g_r_a_m-_f_i_l_e(s)
  166.      if  specified,  or from the first non-option argument on the
  167.      command line.  The -f option may be used multiple  times  on
  168.      the command line.  _G_a_w_k will read the program text as if all
  169.      the _p_r_o_g_r_a_m-_f_i_l_es had been concatenated together.   This  is
  170.      useful for building libraries of AWK functions, without hav-
  171.      ing to include them in each new AWK program that uses  them.
  172.      To  use a library function in a file from a program typed in
  173.      on  the  command  line,  specify  /dev/tty  as  one  of  the
  174.      _p_r_o_g_r_a_m-_f_i_l_es,  type  your  program,  and  end  it with a ^D
  175.      (control-d).
  176.  
  177.      The environment variable AWKPATH specifies a search path  to
  178.      use  when finding source files named with the -f option.  If
  179.      this  variable  does  not  exist,  the   default   path   is
  180.      ".:/usr/lib/awk:/usr/local/lib/awk".   If  a file name given
  181.      to the -f option contains a ``/'' character, no path  search
  182.      is performed.
  183.  
  184.      _G_a_w_k executes AWK programs in the following  order.   First,
  185.      _g_a_w_k  compiles the program into an internal form.  Next, all
  186.      variable assignments specified via the -v  option  are  per-
  187.      formed.   Then, _g_a_w_k executes the code in the BEGIN block(s)
  188.      (if any), and then proceeds to read each file named  in  the
  189.      ARGV  array.   If  there  are  no files named on the command
  190.  
  191.  
  192.  
  193. Free Software FoundationLast change: Apr 15 1993                   3
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200. GAWK(1)                 Utility Commands                  GAWK(1)
  201.  
  202.  
  203.  
  204.      line, _g_a_w_k reads the standard input.
  205.  
  206.      If a filename on the command line has the form _v_a_r=_v_a_l it is
  207.      treated  as  a variable assignment. The variable _v_a_r will be
  208.      assigned the value  _v_a_l.   (This  happens  after  any  BEGIN
  209.      block(s) have been run.) Command line variable assignment is
  210.      most useful for dynamically assigning values  to  the  vari-
  211.      ables  AWK  uses  to control how input is broken into fields
  212.      and records. It is also useful for controlling state if mul-
  213.      tiple passes are needed over a single data file.
  214.  
  215.      If the value of a particular element of ARGV is empty  (""),
  216.      _g_a_w_k skips over it.
  217.  
  218.      For each line in the input, _g_a_w_k tests to see if it  matches
  219.      any  _p_a_t_t_e_r_n  in the AWK program.  For each pattern that the
  220.      line matches, the associated _a_c_t_i_o_n is executed.   The  pat-
  221.      terns are tested in the order they occur in the program.
  222.  
  223.      Finally, after all the input is exhausted, _g_a_w_k executes the
  224.      code in the END block(s) (if any).
  225.  
  226. VARIABLES AND FIELDS
  227.      AWK variables are dynamic; they  come  into  existence  when
  228.      they  are first used. Their values are either floating-point
  229.      numbers or strings, or both, depending  upon  how  they  are
  230.      used.  AWK  also  has  one dimension arrays; multiply dimen-
  231.      sioned arrays may be simulated.  Several  pre-defined  vari-
  232.      ables  are set as a program runs; these will be described as
  233.      needed and summarized below.
  234.  
  235.   Fields
  236.      As each input line  is  read,  _g_a_w_k  splits  the  line  into
  237.      _f_i_e_l_d_s,  using  the  value  of  the FS variable as the field
  238.      separator.   If  FS  is  a  single  character,  fields   are
  239.      separated  by  that character.  Otherwise, FS is expected to
  240.      be a full regular expression.  In the special case  that  FS
  241.      is  a  single  blank, fields are separated by runs of blanks
  242.      and/or tabs.  Note that the value of IGNORECASE (see  below)
  243.      will  also  affect how fields are split when FS is a regular
  244.      expression.
  245.  
  246.      If the FIELDWIDTHS variable is set to a space separated list
  247.      of  numbers, each field is expected to have fixed width, and
  248.      _g_a_w_k will split up the record using  the  specified  widths.
  249.      The  value  of  FS  is ignored.  Assigning a new value to FS
  250.      overrides the use of FIELDWIDTHS, and restores  the  default
  251.      behavior.
  252.  
  253.      Each field in the input line may be referenced by its  posi-
  254.      tion, $1, $2, and so on.  $0 is the whole line. The value of
  255.      a field may be assigned to as  well.   Fields  need  not  be
  256.  
  257.  
  258.  
  259. Free Software FoundationLast change: Apr 15 1993                   4
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266. GAWK(1)                 Utility Commands                  GAWK(1)
  267.  
  268.  
  269.  
  270.      referenced by constants:
  271.  
  272.           n = 5
  273.           print $n
  274.  
  275.      prints the fifth field in the input line.  The  variable  NF
  276.      is set to the total number of fields in the input line.
  277.  
  278.      References to non-existent fields (i.e.  fields  after  $NF)
  279.      produce  the  null-string.  However,  assigning  to  a  non-
  280.      existent field (e.g., $(NF+2) = 5) will increase  the  value
  281.      of NF, create any intervening fields with the null string as
  282.      their value, and cause the value of  $0  to  be  recomputed,
  283.      with the fields being separated by the value of OFS.
  284.  
  285.   Built-in Variables
  286.      AWK's built-in variables are:
  287.  
  288.      ARGC        The number of command line arguments  (does  not
  289.                  include options to _g_a_w_k, or the program source).
  290.  
  291.      ARGIND      The index in ARGV of the current file being pro-
  292.                  cessed.
  293.  
  294.      ARGV        Array of command line arguments.  The  array  is
  295.                  indexed  from 0 to ARGC - 1.  Dynamically chang-
  296.                  ing the contents of ARGV can control  the  files
  297.                  used for data.
  298.  
  299.      CONVFMT     The conversion format for  numbers,  "%.6g",  by
  300.                  default.
  301.  
  302.      ENVIRON     An array containing the values  of  the  current
  303.                  environment.    The  array  is  indexed  by  the
  304.                  environment variables, each  element  being  the
  305.                  value  of  that  variable (e.g., ENVIRON["HOME"]
  306.                  might be /u/arnold).  Changing this  array  does
  307.                  not  affect  the  environment  seen  by programs
  308.                  which _g_a_w_k spawns via redirection  or  the  sys-
  309.                  tem()  function.   (This  may change in a future
  310.                  version of _g_a_w_k.)
  311.  
  312.      ERRNO       If a system error occurs either doing a redirec-
  313.                  tion  for getline, during a read for getline, or
  314.                  during a close, then ERRNO will contain a string
  315.                  describing the error.
  316.  
  317.      FIELDWIDTHS A white-space  separated  list  of  fieldwidths.
  318.                  When  set,  _g_a_w_k parses the input into fields of
  319.                  fixed width, instead of using the value  of  the
  320.                  FS  variable  as the field separator.  The fixed
  321.                  field  width  facility  is  still  experimental;
  322.  
  323.  
  324.  
  325. Free Software FoundationLast change: Apr 15 1993                   5
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332. GAWK(1)                 Utility Commands                  GAWK(1)
  333.  
  334.  
  335.  
  336.                  expect  the  semantics to change as _g_a_w_k evolves
  337.                  over time.
  338.  
  339.      FILENAME    The name of the current input file.  If no files
  340.                  are  specified on the command line, the value of
  341.                  FILENAME is ``-''.
  342.  
  343.      FNR         The input record number  in  the  current  input
  344.                  file.
  345.  
  346.      FS          The input field separator, a blank by default.
  347.  
  348.      IGNORECASE  Controls the  case-sensitivity  of  all  regular
  349.                  expression  operations. If IGNORECASE has a non-
  350.                  zero value,  then  pattern  matching  in  rules,
  351.                  field  splitting  with  FS,  regular  expression
  352.                  matching with ~ and !~, and the gsub(), index(),
  353.                  match(),  split(),  and  sub() pre-defined func-
  354.                  tions will all ignore case  when  doing  regular
  355.                  expression  operations.   Thus, if IGNORECASE is
  356.                  not equal to  zero,  /aB/  matches  all  of  the
  357.                  strings "ab", "aB", "Ab", and "AB".  As with all
  358.                  AWK variables, the initial value  of  IGNORECASE
  359.                  is  zero,  so  all regular expression operations
  360.                  are normally case-sensitive.
  361.  
  362.      NF          The  number  of  fields  in  the  current  input
  363.                  record.
  364.  
  365.      NR          The total number of input records seen so far.
  366.  
  367.      OFMT        The  output  format  for  numbers,  "%.6g",   by
  368.                  default.
  369.  
  370.      OFS         The output field separator, a blank by default.
  371.  
  372.      ORS         The output record separator, by default  a  new-
  373.                  line.
  374.  
  375.      RS          The input record separator, by  default  a  new-
  376.                  line.   RS is exceptional in that only the first
  377.                  character  of  its  string  value  is  used  for
  378.                  separating  records.  (This will probably change
  379.                  in a future release of _g_a_w_k.) If RS  is  set  to
  380.                  the  null  string, then records are separated by
  381.                  blank lines.  When RS is set to the null string,
  382.                  then  the  newline  character  always  acts as a
  383.                  field separator, in addition to  whatever  value
  384.                  FS may have.
  385.  
  386.      RSTART      The index of  the  first  character  matched  by
  387.                  match(); 0 if no match.
  388.  
  389.  
  390.  
  391. Free Software FoundationLast change: Apr 15 1993                   6
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398. GAWK(1)                 Utility Commands                  GAWK(1)
  399.  
  400.  
  401.  
  402.      RLENGTH     The length of the string matched by match();  -1
  403.                  if no match.
  404.  
  405.      SUBSEP      The character used  to  separate  multiple  sub-
  406.                  scripts in array elements, by default "\034".
  407.  
  408.   Arrays
  409.      Arrays are subscripted with  an  expression  between  square
  410.      brackets ([ and ]).  If the expression is an expression list
  411.      (_e_x_p_r, _e_x_p_r ...) then the array subscript is a  string  con-
  412.      sisting  of  the concatenation of the (string) value of each
  413.      expression, separated by the value of the  SUBSEP  variable.
  414.      This  facility  is  used  to  simulate  multiply dimensioned
  415.      arrays. For example:
  416.  
  417.           i = "A" ; j = "B" ; k = "C"
  418.           x[i, j, k] = "hello, world\n"
  419.  
  420.      assigns the string "hello, world\n" to the  element  of  the
  421.      array  x  which  is indexed by the string "A\034B\034C". All
  422.      arrays in  AWK  are  associative,  i.e.  indexed  by  string
  423.      values.
  424.  
  425.      The special operator in may be used in an if or while state-
  426.      ment to see if an array has an index consisting of a partic-
  427.      ular value.
  428.  
  429.           if (val in array)
  430.                print array[val]
  431.  
  432.      If the array has multiple subscripts, use (i, j) in array.
  433.  
  434.      The in construct may also be used in a for loop  to  iterate
  435.      over all the elements of an array.
  436.  
  437.      An element may be deleted from an  array  using  the  delete
  438.      statement.
  439.  
  440.   Variable Typing And Conversion
  441.      Variables and fields may be  (floating  point)  numbers,  or
  442.      strings, or both. How the value of a variable is interpreted
  443.      depends upon its context. If used in a  numeric  expression,
  444.      it  will be treated as a number, if used as a string it will
  445.      be treated as a string.
  446.  
  447.      To force a variable to be treated as a number, add 0 to  it;
  448.      to  force  it to be treated as a string, concatenate it with
  449.      the null string.
  450.  
  451.      When a string must be converted to a number, the  conversion
  452.      is  accomplished  using _a_t_o_f(3).  A number is converted to a
  453.      string by using the value of CONVFMT as a format string  for
  454.  
  455.  
  456.  
  457. Free Software FoundationLast change: Apr 15 1993                   7
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464. GAWK(1)                 Utility Commands                  GAWK(1)
  465.  
  466.  
  467.  
  468.      _s_p_r_i_n_t_f(3),  with  the  numeric value of the variable as the
  469.      argument.  However, even  though  all  numbers  in  AWK  are
  470.      floating-point,  integral  values  are  _a_l_w_a_y_s  converted as
  471.      integers.  Thus, given
  472.  
  473.           CONVFMT = "%2.2f"
  474.           a = 12
  475.           b = a ""
  476.  
  477.      the variable b has a value of "12" and not "12.00".
  478.  
  479.      _G_a_w_k performs comparisons as follows: If two  variables  are
  480.      numeric,  they  are  compared  numerically.  If one value is
  481.      numeric and the other has a string value that is a ``numeric
  482.      string,''  then comparisons are also done numerically.  Oth-
  483.      erwise, the numeric value is converted to  a  string  and  a
  484.      string  comparison  is performed.  Two strings are compared,
  485.      of course, as strings.  According  to  the  POSIX  standard,
  486.      even  if  two  strings  are  numeric strings, a numeric com-
  487.      parison is performed.  However, this is  clearly  incorrect,
  488.      and _g_a_w_k does not do this.
  489.  
  490.      Uninitialized variables have the numeric  value  0  and  the
  491.      string value "" (the null, or empty, string).
  492.  
  493. PATTERNS AND ACTIONS
  494.      AWK is a line oriented language. The  pattern  comes  first,
  495.      and then the action. Action statements are enclosed in { and
  496.      }.  Either the pattern may be missing, or the action may  be
  497.      missing,  but,  of course, not both. If the pattern is miss-
  498.      ing, the action will be executed for every  single  line  of
  499.      input.  A missing action is equivalent to
  500.  
  501.           { print }
  502.  
  503.      which prints the entire line.
  504.  
  505.      Comments begin with the ``#'' character, and continue  until
  506.      the  end  of  the line.  Blank lines may be used to separate
  507.      statements.  Normally, a statement ends with a newline, how-
  508.      ever,  this  is  not  the  case for lines ending in a ``,'',
  509.      ``{'', ``?'', ``:'', ``&&'', or ``||''.  Lines ending in  do
  510.      or  else  also have their statements automatically continued
  511.      on the following line.  In other cases, a line can  be  con-
  512.      tinued  by ending it with a ``\'', in which case the newline
  513.      will be ignored.
  514.  
  515.      Multiple statements may be put on  one  line  by  separating
  516.      them  with  a  ``;''.   This  applies to both the statements
  517.      within the action part of a pattern-action pair  (the  usual
  518.      case), and to the pattern-action statements themselves.
  519.  
  520.  
  521.  
  522.  
  523. Free Software FoundationLast change: Apr 15 1993                   8
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530. GAWK(1)                 Utility Commands                  GAWK(1)
  531.  
  532.  
  533.  
  534.   Patterns
  535.      AWK patterns may be one of the following:
  536.  
  537.           BEGIN
  538.           END
  539.           /_r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n/
  540.           _r_e_l_a_t_i_o_n_a_l _e_x_p_r_e_s_s_i_o_n
  541.           _p_a_t_t_e_r_n && _p_a_t_t_e_r_n
  542.           _p_a_t_t_e_r_n || _p_a_t_t_e_r_n
  543.           _p_a_t_t_e_r_n ? _p_a_t_t_e_r_n : _p_a_t_t_e_r_n
  544.           (_p_a_t_t_e_r_n)
  545.           ! _p_a_t_t_e_r_n
  546.           _p_a_t_t_e_r_n_1, _p_a_t_t_e_r_n_2
  547.  
  548.      BEGIN and END are two special kinds of  patterns  which  are
  549.      not tested against the input.  The action parts of all BEGIN
  550.      patterns are merged as if all the statements had been  writ-
  551.      ten in a single BEGIN block. They are executed before any of
  552.      the input is read. Similarly, all the END blocks are merged,
  553.      and  executed  when  all  the input is exhausted (or when an
  554.      exit statement is executed).  BEGIN and END patterns  cannot
  555.      be  combined  with  other  patterns  in pattern expressions.
  556.      BEGIN and END patterns cannot have missing action parts.
  557.  
  558.      For /_r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n/ patterns, the associated  statement
  559.      is  executed  for  each  input line that matches the regular
  560.      expression.  Regular expressions are the same  as  those  in
  561.      _e_g_r_e_p(1), and are summarized below.
  562.  
  563.      A _r_e_l_a_t_i_o_n_a_l _e_x_p_r_e_s_s_i_o_n may use any of the operators defined
  564.      below  in  the  section  on  actions.   These generally test
  565.      whether certain fields match certain regular expressions.
  566.  
  567.      The &&, ||, and ! operators are logical AND, logical OR, and
  568.      logical  NOT,  respectively, as in C.  They do short-circuit
  569.      evaluation, also as in C, and are used  for  combining  more
  570.      primitive   pattern   expressions.  As  in  most  languages,
  571.      parentheses may be used to change the order of evaluation.
  572.  
  573.      The ?: operator is like the same operator in C. If the first
  574.      pattern  is  true  then  the pattern used for testing is the
  575.      second pattern, otherwise it is the third. Only one  of  the
  576.      second and third patterns is evaluated.
  577.  
  578.      The _p_a_t_t_e_r_n_1, _p_a_t_t_e_r_n_2 form of an  expression  is  called  a
  579.      range pattern.  It matches all input records starting with a
  580.      line that matches _p_a_t_t_e_r_n_1, and continuing  until  a  record
  581.      that  matches  _p_a_t_t_e_r_n_2, inclusive. It does not combine with
  582.      any other sort of pattern expression.
  583.  
  584.   Regular Expressions
  585.      Regular expressions are the extended kind  found  in  _e_g_r_e_p.
  586.  
  587.  
  588.  
  589. Free Software FoundationLast change: Apr 15 1993                   9
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596. GAWK(1)                 Utility Commands                  GAWK(1)
  597.  
  598.  
  599.  
  600.      They are composed of characters as follows:
  601.  
  602.      _c          matches the non-metacharacter _c.
  603.  
  604.      _\_c         matches the literal character _c.
  605.  
  606.      .          matches any character except newline.
  607.  
  608.      ^          matches the beginning of a line or a string.
  609.  
  610.      $          matches the end of a line or a string.
  611.  
  612.      [_a_b_c...]   character class, matches any  of  the  characters
  613.                 _a_b_c....
  614.  
  615.      [^_a_b_c...]  negated character class,  matches  any  character
  616.                 except _a_b_c... and newline.
  617.  
  618.      _r_1|_r_2      alternation: matches either _r_1 or _r_2.
  619.  
  620.      _r_1_r_2       concatenation: matches _r_1, and then _r_2.
  621.  
  622.      _r+         matches one or more _r's.
  623.  
  624.      _r*         matches zero or more _r's.
  625.  
  626.      _r?         matches zero or one _r's.
  627.  
  628.      (_r)        grouping: matches _r.
  629.  
  630.      The escape sequences that are valid in string constants (see
  631.      below) are also legal in regular expressions.
  632.  
  633.   Actions
  634.      Action statements are enclosed in braces, { and  }.   Action
  635.      statements consist of the usual assignment, conditional, and
  636.      looping statements found in most languages.  The  operators,
  637.      control  statements,  and  input/output statements available
  638.      are patterned after those in C.
  639.  
  640.   Operators
  641.      The operators in AWK, in order of increasing precedence, are
  642.  
  643.      = += -=
  644.      *= /= %= ^= Assignment.  Both  absolute  assignment  (_v_a_r  =
  645.                  _v_a_l_u_e) and operator-assignment (the other forms)
  646.                  are supported.
  647.  
  648.      ?:          The C conditional expression. This has the  form
  649.                  _e_x_p_r_1  ?  _e_x_p_r_2  :  _e_x_p_r_3. If _e_x_p_r_1 is true, the
  650.                  value of the expression is _e_x_p_r_2,  otherwise  it
  651.                  is  _e_x_p_r_3.   Only  one  of  _e_x_p_r_2  and  _e_x_p_r_3 is
  652.  
  653.  
  654.  
  655. Free Software FoundationLast change: Apr 15 1993                  10
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662. GAWK(1)                 Utility Commands                  GAWK(1)
  663.  
  664.  
  665.  
  666.                  evaluated.
  667.  
  668.      ||          Logical OR.
  669.  
  670.      &&          Logical AND.
  671.  
  672.      ~ !~        Regular expression match, negated match.   NOTE:
  673.                  Do not use a constant regular expression (/foo/)
  674.                  on the left-hand side of a ~ or  !~.   Only  use
  675.                  one  on  the  right-hand  side.   The expression
  676.                  /foo/ ~ _e_x_p has  the  same  meaning  as  (($0  ~
  677.                  /foo/)  ~  _e_x_p).   This  is usually _n_o_t what was
  678.                  intended.
  679.  
  680.      < >
  681.      <= >=
  682.      != ==       The regular relational operators.
  683.  
  684.      _b_l_a_n_k       String concatenation.
  685.  
  686.      + -         Addition and subtraction.
  687.  
  688.      * / %       Multiplication, division, and modulus.
  689.  
  690.      + - !       Unary plus, unary minus, and logical negation.
  691.  
  692.      ^           Exponentiation (** may also be used, and **= for
  693.                  the assignment operator).
  694.  
  695.      ++ --       Increment and decrement, both prefix  and  post-
  696.                  fix.
  697.  
  698.      $           Field reference.
  699.  
  700.   Control Statements
  701.      The control statements are as follows:
  702.  
  703.           if (_c_o_n_d_i_t_i_o_n) _s_t_a_t_e_m_e_n_t [ else _s_t_a_t_e_m_e_n_t ]
  704.           while (_c_o_n_d_i_t_i_o_n) _s_t_a_t_e_m_e_n_t
  705.           do _s_t_a_t_e_m_e_n_t while (_c_o_n_d_i_t_i_o_n)
  706.           for (_e_x_p_r_1; _e_x_p_r_2; _e_x_p_r_3) _s_t_a_t_e_m_e_n_t
  707.           for (_v_a_r in _a_r_r_a_y) _s_t_a_t_e_m_e_n_t
  708.           break
  709.           continue
  710.           delete _a_r_r_a_y[_i_n_d_e_x]
  711.           exit [ _e_x_p_r_e_s_s_i_o_n ]
  712.           { _s_t_a_t_e_m_e_n_t_s }
  713.  
  714.   I/O Statements
  715.      The input/output statements are as follows:
  716.  
  717.  
  718.  
  719.  
  720.  
  721. Free Software FoundationLast change: Apr 15 1993                  11
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728. GAWK(1)                 Utility Commands                  GAWK(1)
  729.  
  730.  
  731.  
  732.      close(_f_i_l_e_n_a_m_e)       Close file (or pipe, see below).
  733.  
  734.      getline               Set $0 from next input record; set NF,
  735.                            NR, FNR.
  736.  
  737.      getline <_f_i_l_e         Set $0 from next record of  _f_i_l_e;  set
  738.                            NF.
  739.  
  740.      getline _v_a_r           Set _v_a_r from next  input  record;  set
  741.                            NF, FNR.
  742.  
  743.      getline _v_a_r <_f_i_l_e     Set _v_a_r from next record of _f_i_l_e.
  744.  
  745.      next                  Stop  processing  the  current   input
  746.                            record.  The next input record is read
  747.                            and processing starts  over  with  the
  748.                            first  pattern  in the AWK program. If
  749.                            the end of the input data is  reached,
  750.                            the  END  block(s),  if  any, are exe-
  751.                            cuted.
  752.  
  753.      next file             Stop  processing  the  current   input
  754.                            file.   The  next  input  record  read
  755.                            comes  from  the  next   input   file.
  756.                            FILENAME  is  updated, FNR is reset to
  757.                            1, and processing starts over with the
  758.                            first  pattern  in the AWK program. If
  759.                            the end of the input data is  reached,
  760.                            the  END  block(s),  if  any, are exe-
  761.                            cuted.
  762.  
  763.      print                 Prints the current record.
  764.  
  765.      print _e_x_p_r-_l_i_s_t       Prints expressions.
  766.  
  767.      print _e_x_p_r-_l_i_s_t >_f_i_l_e Prints expressions on _f_i_l_e.
  768.  
  769.      printf _f_m_t, _e_x_p_r-_l_i_s_t Format and print.
  770.  
  771.      printf _f_m_t, _e_x_p_r-_l_i_s_t >_f_i_l_e
  772.                            Format and print on _f_i_l_e.
  773.  
  774.      system(_c_m_d-_l_i_n_e)      Execute  the  command  _c_m_d-_l_i_n_e,   and
  775.                            return the exit status.  (This may not
  776.                            be available on non-POSIX systems.)
  777.  
  778.      Other input/output redirections are also allowed. For  print
  779.      and  printf, >>_f_i_l_e appends output to the _f_i_l_e, while | _c_o_m_-
  780.      _m_a_n_d writes on a pipe.  In a similar fashion, _c_o_m_m_a_n_d | get-
  781.      line  pipes  into  getline.  Getline will return 0 on end of
  782.      file, and -1 on an error.
  783.  
  784.  
  785.  
  786.  
  787. Free Software FoundationLast change: Apr 15 1993                  12
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794. GAWK(1)                 Utility Commands                  GAWK(1)
  795.  
  796.  
  797.  
  798.   The _p_r_i_n_t_f Statement
  799.      The AWK versions of the printf statement and sprintf() func-
  800.      tion  (see below) accept the following conversion specifica-
  801.      tion formats:
  802.  
  803.      %c   An ASCII character.  If the argument  used  for  %c  is
  804.           numeric,  it  is  treated  as  a character and printed.
  805.           Otherwise, the argument is assumed to be a string,  and
  806.           the only first character of that string is printed.
  807.  
  808.      %d   A decimal number (the integer part).
  809.  
  810.      %i   Just like %d.
  811.  
  812.      %e   A floating point number of the form [-]d.ddddddE[+-]dd.
  813.  
  814.      %f   A floating point number of the form [-]ddd.dddddd.
  815.  
  816.      %g   Use e or f conversion, whichever is shorter, with  non-
  817.           significant zeros suppressed.
  818.  
  819.      %o   An unsigned octal number (again, an integer).
  820.  
  821.      %s   A character string.
  822.  
  823.      %x   An unsigned hexadecimal number (an integer).
  824.  
  825.      %X   Like %x, but using ABCDEF instead of abcdef.
  826.  
  827.      %%   A single % character; no argument is converted.
  828.  
  829.      There are  optional,  additional  parameters  that  may  lie
  830.      between the % and the control letter:
  831.  
  832.      -    The expression  should  be  left-justified  within  its
  833.           field.
  834.  
  835.      _w_i_d_t_h
  836.           The field should be padded to this width. If the number
  837.           has  a leading zero, then the field will be padded with
  838.           zeros.  Otherwise it is padded with blanks.
  839.  
  840.      ._p_r_e_c
  841.           A number indicating the maximum  width  of  strings  or
  842.           digits to the right of the decimal point.
  843.  
  844.      The dynamic _w_i_d_t_h  and  _p_r_e_c  capabilities  of  the  ANSI  C
  845.      printf() routines are supported.  A * in place of either the
  846.      width or prec specifications will cause their values  to  be
  847.      taken from the argument list to printf or sprintf().
  848.  
  849.  
  850.  
  851.  
  852.  
  853. Free Software FoundationLast change: Apr 15 1993                  13
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860. GAWK(1)                 Utility Commands                  GAWK(1)
  861.  
  862.  
  863.  
  864.   Special File Names
  865.      When doing I/O redirection from either print or printf  into
  866.      a  file, or via getline from a file, _g_a_w_k recognizes certain
  867.      special filenames internally.  These filenames allow  access
  868.      to  open  file descriptors inherited from _g_a_w_k's parent pro-
  869.      cess (usually the shell).  Other special  filenames  provide
  870.      access  information  about  the  running  gawk process.  The
  871.      filenames are:
  872.  
  873.      /dev/pid    Reading this file returns the process ID of  the
  874.                  current  process,  in decimal, terminated with a
  875.                  newline.
  876.  
  877.      /dev/ppid   Reading this file returns the parent process  ID
  878.                  of  the  current process, in decimal, terminated
  879.                  with a newline.
  880.  
  881.      /dev/pgrpid Reading this file returns the process  group  ID
  882.                  of  the  current process, in decimal, terminated
  883.                  with a newline.
  884.  
  885.      /dev/user   Reading this file returns a single  record  ter-
  886.                  minated   with   a   newline.   The  fields  are
  887.                  separated with blanks.  $1 is the value  of  the
  888.                  _g_e_t_u_i_d(2)  system  call,  $2 is the value of the
  889.                  _g_e_t_e_u_i_d(2) system call, $3 is the value  of  the
  890.                  _g_e_t_g_i_d(2)  system  call,  and $4 is the value of
  891.                  the _g_e_t_e_g_i_d(2) system call.  If  there  are  any
  892.                  additional   fields,  they  are  the  group  IDs
  893.                  returned by _g_e_t_g_r_o_u_p_s(2).  (Multiple groups  may
  894.                  not be supported on all systems.)
  895.  
  896.      /dev/stdin  The standard input.
  897.  
  898.      /dev/stdout The standard output.
  899.  
  900.      /dev/stderr The standard error output.
  901.  
  902.      /dev/fd/_n   The file associated with the open file  descrip-
  903.                  tor _n.
  904.  
  905.      These are particularly useful for error messages. For  exam-
  906.      ple:
  907.  
  908.           print "You blew it!" > "/dev/stderr"
  909.  
  910.      whereas you would otherwise have to use
  911.  
  912.           print "You blew it!" | "cat 1>&2"
  913.  
  914.      These file names may also be used on  the  command  line  to
  915.      name data files.
  916.  
  917.  
  918.  
  919. Free Software FoundationLast change: Apr 15 1993                  14
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926. GAWK(1)                 Utility Commands                  GAWK(1)
  927.  
  928.  
  929.  
  930.   Numeric Functions
  931.      AWK has the following pre-defined arithmetic functions:
  932.  
  933.      atan2(_y, _x) returns the arctangent of _y/_x in radians.
  934.  
  935.      cos(_e_x_p_r)   returns the cosine in radians.
  936.  
  937.      exp(_e_x_p_r)   the exponential function.
  938.  
  939.      int(_e_x_p_r)   truncates to integer.
  940.  
  941.      log(_e_x_p_r)   the natural logarithm function.
  942.  
  943.      rand()      returns a random number between 0 and 1.
  944.  
  945.      sin(_e_x_p_r)   returns the sine in radians.
  946.  
  947.      sqrt(_e_x_p_r)  the square root function.
  948.  
  949.      srand(_e_x_p_r) use _e_x_p_r as a new seed  for  the  random  number
  950.                  generator.  If  no _e_x_p_r is provided, the time of
  951.                  day will be used.  The return value is the  pre-
  952.                  vious seed for the random number generator.
  953.  
  954.   String Functions
  955.      AWK has the following pre-defined string functions:
  956.  
  957.      gsub(_r, _s, _t)           for each substring matching the reg-
  958.                              ular  expression  _r in the string _t,
  959.                              substitute the string _s, and  return
  960.                              the  number  of substitutions.  If _t
  961.                              is not supplied, use $0.
  962.  
  963.      index(_s, _t)             returns the index of the string _t in
  964.                              the  string  _s,  or  0  if  _t is not
  965.                              present.
  966.  
  967.      length(_s)               returns the length of the string  _s,
  968.                              or the length of $0 if _s is not sup-
  969.                              plied.
  970.  
  971.      match(_s, _r)             returns the position in _s where  the
  972.                              regular expression _r occurs, or 0 if
  973.                              _r  is  not  present,  and  sets  the
  974.                              values of RSTART and RLENGTH.
  975.  
  976.      split(_s, _a, _r)          splits the string _s into the array _a
  977.                              on  the  regular  expression  _r, and
  978.                              returns the number of fields.  If  _r
  979.                              is omitted, FS is used instead.
  980.  
  981.      sprintf(_f_m_t, _e_x_p_r-_l_i_s_t) prints _e_x_p_r-_l_i_s_t according  to  _f_m_t,
  982.  
  983.  
  984.  
  985. Free Software FoundationLast change: Apr 15 1993                  15
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992. GAWK(1)                 Utility Commands                  GAWK(1)
  993.  
  994.  
  995.  
  996.                              and returns the resulting string.
  997.  
  998.      sub(_r, _s, _t)            just like gsub(), but only the first
  999.                              matching substring is replaced.
  1000.  
  1001.      substr(_s, _i, _n)         returns the _n-character substring of
  1002.                              _s  starting  at _i.  If _n is omitted,
  1003.                              the rest of _s is used.
  1004.  
  1005.      tolower(_s_t_r)            returns a copy of  the  string  _s_t_r,
  1006.                              with  all  the upper-case characters
  1007.                              in   _s_t_r   translated    to    their
  1008.                              corresponding   lower-case  counter-
  1009.                              parts.   Non-alphabetic   characters
  1010.                              are left unchanged.
  1011.  
  1012.      toupper(_s_t_r)            returns a copy of  the  string  _s_t_r,
  1013.                              with  all  the lower-case characters
  1014.                              in   _s_t_r   translated    to    their
  1015.                              corresponding   upper-case  counter-
  1016.                              parts.   Non-alphabetic   characters
  1017.                              are left unchanged.
  1018.  
  1019.   Time Functions
  1020.      Since one of the primary uses of AWK programs is  processing
  1021.      log files that contain time stamp information, _g_a_w_k provides
  1022.      the following two functions for obtaining  time  stamps  and
  1023.      formatting them.
  1024.  
  1025.      systime() returns the current time of day as the  number  of
  1026.                seconds  since the Epoch (Midnight UTC, January 1,
  1027.                1970 on POSIX systems).
  1028.  
  1029.      strftime(_f_o_r_m_a_t, _t_i_m_e_s_t_a_m_p)
  1030.                formats _t_i_m_e_s_t_a_m_p according to  the  specification
  1031.                in  _f_o_r_m_a_t.   The  _t_i_m_e_s_t_a_m_p should be of the same
  1032.                form as returned by systime().   If  _t_i_m_e_s_t_a_m_p  is
  1033.                missing, the current time of day is used.  See the
  1034.                specification for the strftime() function in  ANSI
  1035.                C  for  the format conversions that are guaranteed
  1036.                to  be  available.   A  public-domain  version  of
  1037.                _s_t_r_f_t_i_m_e(3) and a man page for it are shipped with
  1038.                _g_a_w_k; if that version was used to build _g_a_w_k, then
  1039.                all  of the conversions described in that man page
  1040.                are available to _g_a_w_k.
  1041.  
  1042.   String Constants
  1043.      String constants in AWK are sequences of characters enclosed
  1044.      between  double  quotes  ("). Within strings, certain _e_s_c_a_p_e
  1045.      _s_e_q_u_e_n_c_e_s are recognized, as in C. These are:
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051. Free Software FoundationLast change: Apr 15 1993                  16
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058. GAWK(1)                 Utility Commands                  GAWK(1)
  1059.  
  1060.  
  1061.  
  1062.      \\   A literal backslash.
  1063.  
  1064.      \a   The ``alert'' character; usually the ASCII BEL  charac-
  1065.           ter.
  1066.  
  1067.      \b   backspace.
  1068.  
  1069.      \f   form-feed.
  1070.  
  1071.      \n   new line.
  1072.  
  1073.      \r   carriage return.
  1074.  
  1075.      \t   horizontal tab.
  1076.  
  1077.      \v   vertical tab.
  1078.  
  1079.      \x_h_e_x _d_i_g_i_t_s
  1080.           The character represented by the string of  hexadecimal
  1081.           digits  following  the \x.  As in ANSI C, all following
  1082.           hexadecimal digits are considered part  of  the  escape
  1083.           sequence.  (This feature should tell us something about
  1084.           language design by  committee.)  E.g.,  "\x1B"  is  the
  1085.           ASCII ESC (escape) character.
  1086.  
  1087.      \_d_d_d The character represented by the  1-,  2-,  or  3-digit
  1088.           sequence  of octal digits. E.g. "\033" is the ASCII ESC
  1089.           (escape) character.
  1090.  
  1091.      \_c   The literal character _c.
  1092.  
  1093.      The escape sequences may also be used inside constant  regu-
  1094.      lar  expressions  (e.g.,  /[ \t\f\n\r\v]/ matches whitespace
  1095.      characters).
  1096.  
  1097. FUNCTIONS
  1098.      Functions in AWK are defined as follows:
  1099.  
  1100.           function _n_a_m_e(_p_a_r_a_m_e_t_e_r _l_i_s_t) { _s_t_a_t_e_m_e_n_t_s }
  1101.  
  1102.      Functions are executed when called from  within  the  action
  1103.      parts  of  regular pattern-action statements. Actual parame-
  1104.      ters supplied in the function call are used  to  instantiate
  1105.      the  formal parameters declared in the function.  Arrays are
  1106.      passed by reference, other variables are passed by value.
  1107.  
  1108.      Since  functions  were  not  originally  part  of  the   AWK
  1109.      language,  the  provision  for  local  variables  is  rather
  1110.      clumsy: They are declared as extra parameters in the parame-
  1111.      ter list. The convention is to separate local variables from
  1112.      real parameters by extra spaces in the parameter  list.  For
  1113.      example:
  1114.  
  1115.  
  1116.  
  1117. Free Software FoundationLast change: Apr 15 1993                  17
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124. GAWK(1)                 Utility Commands                  GAWK(1)
  1125.  
  1126.  
  1127.  
  1128.           function  f(p, q,     a, b) { # a & b are local
  1129.                          ..... }
  1130.  
  1131.           /abc/     { ... ; f(1, 2) ; ... }
  1132.  
  1133.      The left parenthesis in  a  function  call  is  required  to
  1134.      immediately  follow the function name, without any interven-
  1135.      ing white space.  This is to  avoid  a  syntactic  ambiguity
  1136.      with  the concatenation operator.  This restriction does not
  1137.      apply to the built-in functions listed above.
  1138.  
  1139.      Functions may call each other and may be  recursive.   Func-
  1140.      tion  parameters  used as local variables are initialized to
  1141.      the null string and the number zero  upon  function  invoca-
  1142.      tion.
  1143.  
  1144.      The word func may be used in place of function.
  1145.  
  1146. EXAMPLES
  1147.      Print and sort the login names of all users:
  1148.  
  1149.           BEGIN     { FS = ":" }
  1150.                { print $1 | "sort" }
  1151.  
  1152.      Count lines in a file:
  1153.  
  1154.                { nlines++ }
  1155.           END  { print nlines }
  1156.  
  1157.      Precede each line by its number in the file:
  1158.  
  1159.           { print FNR, $0 }
  1160.  
  1161.      Concatenate and line number (a variation on a theme):
  1162.  
  1163.           { print NR, $0 }
  1164.  
  1165. SEE ALSO
  1166.      _e_g_r_e_p(1)
  1167.  
  1168.      _T_h_e _A_W_K _P_r_o_g_r_a_m_m_i_n_g _L_a_n_g_u_a_g_e, Alfred V. Aho, Brian  W.  Ker-
  1169.      nighan,  Peter  J. Weinberger, Addison-Wesley, 1988. ISBN 0-
  1170.      201-07981-X.
  1171.  
  1172.      _T_h_e  _G_A_W_K  _M_a_n_u_a_l,  Edition  0.15,  published  by  the  Free
  1173.      Software Foundation, 1993.
  1174.  
  1175. POSIX COMPATIBILITY
  1176.      A primary goal for _g_a_w_k  is  compatibility  with  the  POSIX
  1177.      standard,  as  well  as with the latest version of UNIX _a_w_k.
  1178.      To this end, _g_a_w_k incorporates the  following  user  visible
  1179.      features  which  are  not described in the AWK book, but are
  1180.  
  1181.  
  1182.  
  1183. Free Software FoundationLast change: Apr 15 1993                  18
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190. GAWK(1)                 Utility Commands                  GAWK(1)
  1191.  
  1192.  
  1193.  
  1194.      part of _a_w_k in System V Release 4,  and  are  in  the  POSIX
  1195.      standard.
  1196.  
  1197.      The -v option for assigning variables before program  execu-
  1198.      tion  starts  is  new.  The book indicates that command line
  1199.      variable assignment happens when _a_w_k  would  otherwise  open
  1200.      the  argument  as  a file, which is after the BEGIN block is
  1201.      executed.  However, in earlier implementations, when such an
  1202.      assignment  appeared  before  any file names, the assignment
  1203.      would happen _b_e_f_o_r_e the BEGIN block was  run.   Applications
  1204.      came  to depend on this ``feature.'' When _a_w_k was changed to
  1205.      match its documentation, this option was added to accomodate
  1206.      applications  that  depended  upon  the old behavior.  (This
  1207.      feature was agreed upon by both the AT&T  and  GNU  develop-
  1208.      ers.)
  1209.  
  1210.      The -W option for implementation specific features  is  from
  1211.      the POSIX standard.
  1212.  
  1213.      When processing arguments,  _g_a_w_k  uses  the  special  option
  1214.      ``--''  to signal the end of arguments, and warns about, but
  1215.      otherwise ignores, undefined options.
  1216.  
  1217.      The AWK book does not define the return  value  of  srand().
  1218.      The  System  V  Release 4 version of UNIX _a_w_k (and the POSIX
  1219.      standard) has it return the seed  it  was  using,  to  allow
  1220.      keeping  track of random number sequences. Therefore srand()
  1221.      in _g_a_w_k also returns its current seed.
  1222.  
  1223.      Other new features are: The use of multiple -f options (from
  1224.      MKS _a_w_k); the ENVIRON array; the \a, and \v escape sequences
  1225.      (done originally in _g_a_w_k and  fed  back  into  AT&T's);  the
  1226.      tolower()  and toupper() built-in functions (from AT&T); and
  1227.      the ANSI C conversion specifications in printf  (done  first
  1228.      in AT&T's version).
  1229.  
  1230. GNU EXTENSIONS
  1231.      _G_a_w_k has some extensions to POSIX _a_w_k.  They  are  described
  1232.      in  this  section.  All the extensions described here can be
  1233.      disabled by invoking _g_a_w_k with the -W compat option.
  1234.  
  1235.      The following features of _g_a_w_k are not  available  in  POSIX
  1236.      _a_w_k.
  1237.  
  1238.           o+ The \x escape sequence.
  1239.  
  1240.           o+ The systime() and strftime() functions.
  1241.  
  1242.           o+ The special file names available for I/O  redirection
  1243.             are not recognized.
  1244.  
  1245.           o+ The ARGIND and ERRNO variables are not special.
  1246.  
  1247.  
  1248.  
  1249. Free Software FoundationLast change: Apr 15 1993                  19
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256. GAWK(1)                 Utility Commands                  GAWK(1)
  1257.  
  1258.  
  1259.  
  1260.           o+ The IGNORECASE variable and its side-effects are  not
  1261.             available.
  1262.  
  1263.           o+ The FIELDWIDTHS variable and fixed width field split-
  1264.             ting.
  1265.  
  1266.           o+ No path search is performed for files named  via  the
  1267.             -f  option.   Therefore the AWKPATH environment vari-
  1268.             able is not special.
  1269.  
  1270.           o+ The use of next file to  abandon  processing  of  the
  1271.             current input file.
  1272.  
  1273.      The AWK book does not define the return value of the close()
  1274.      function.   _G_a_w_k's close() returns the value from _f_c_l_o_s_e(3),
  1275.      or _p_c_l_o_s_e(3), when closing a file or pipe, respectively.
  1276.  
  1277.      When _g_a_w_k is invoked with the -W compat option,  if  the  _f_s
  1278.      argument  to  the -F option is ``t'', then FS will be set to
  1279.      the tab character.  Since this  is  a  rather  ugly  special
  1280.      case,  it  is  not the default behavior.  This behavior also
  1281.      does not occur if -Wposix has been specified.
  1282.  
  1283. HISTORICAL FEATURES
  1284.      There are two features  of  historical  AWK  implementations
  1285.      that  _g_a_w_k  supports.   First,  it  is  possible to call the
  1286.      length() built-in function not only with  no  argument,  but
  1287.      even without parentheses!  Thus,
  1288.  
  1289.           a = length
  1290.  
  1291.      is the same as either of
  1292.  
  1293.           a = length()
  1294.           a = length($0)
  1295.  
  1296.      This feature is marked as ``deprecated'' in the POSIX  stan-
  1297.      dard,  and _g_a_w_k will issue a warning about its use if -Wlint
  1298.      is specified on the command line.
  1299.  
  1300.      The other feature is the use of the continue statement  out-
  1301.      side  the body of a while, for, or do loop.  Traditional AWK
  1302.      implementations have treated such usage as equivalent to the
  1303.      next statement.  _G_a_w_k will support this usage if -Wposix has
  1304.      not been specified.
  1305.  
  1306. BUGS
  1307.      The -F option is not necessary given the command line  vari-
  1308.      able  assignment feature; it remains only for backwards com-
  1309.      patibility.
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315. Free Software FoundationLast change: Apr 15 1993                  20
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322. GAWK(1)                 Utility Commands                  GAWK(1)
  1323.  
  1324.  
  1325.  
  1326.      If your system actually has  support  for  /dev/fd  and  the
  1327.      associated  /dev/stdin,  /dev/stdout, and /dev/stderr files,
  1328.      you may get different output from _g_a_w_k than you would get on
  1329.      a  system  without  those files.  When _g_a_w_k interprets these
  1330.      files internally, it synchronizes  output  to  the  standard
  1331.      output  with  output  to /dev/stdout, while on a system with
  1332.      those files, the output is actually to different open files.
  1333.      Caveat Emptor.
  1334.  
  1335. VERSION INFORMATION
  1336.      This man page documents _g_a_w_k, version 2.15.
  1337.  
  1338.      Starting with the 2.15 version of _g_a_w_k, the -c, -V, -C,  -a,
  1339.      and -e options of the 2.11 version are no longer recognized.
  1340.  
  1341. AUTHORS
  1342.      The original version of UNIX _a_w_k  was  designed  and  imple-
  1343.      mented  by Alfred Aho, Peter Weinberger, and Brian Kernighan
  1344.      of AT&T Bell Labs. Brian Kernighan continues to maintain and
  1345.      enhance it.
  1346.  
  1347.      Paul Rubin and Jay Fenlason, of the  Free  Software  Founda-
  1348.      tion, wrote _g_a_w_k, to be compatible with the original version
  1349.      of _a_w_k distributed in Seventh Edition UNIX.  John Woods con-
  1350.      tributed a number of bug fixes.  David Trueman, with contri-
  1351.      butions from Arnold Robbins, made _g_a_w_k compatible  with  the
  1352.      new version of UNIX _a_w_k.
  1353.  
  1354.      The initial DOS port was done by Conrad Kwok and Scott  Gar-
  1355.      finkle.   Scott  Deifik  is the current DOS maintainer.  Pat
  1356.      Rankin did the port to VMS, and Michal  Jaegermann  did  the
  1357.      port to the Atari ST.
  1358.  
  1359. ACKNOWLEDGEMENTS
  1360.      Brian Kernighan of Bell Labs  provided  valuable  assistance
  1361.      during testing and debugging.  We thank him.
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381. Free Software FoundationLast change: Apr 15 1993                  21
  1382.  
  1383.  
  1384.  
  1385.