home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / gawk2.0.t.Z / gawk2.0.t / gawk.man < prev    next >
Text File  |  1989-04-06  |  36KB  |  937 lines

  1.  
  2.  
  3.  
  4.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  5.  
  6.  
  7.  
  8.      NAME
  9.           gawk - pattern scanning and processing language
  10.  
  11.      SYNOPSIS
  12.           ggaawwkk [ --FF_f_s ] --ff _p_r_o_g_r_a_m-_f_i_l_e [ --ff _p_r_o_g_r_a_m-_f_i_l_e ... ] [ ---- ]
  13.           file ...
  14.           ggaawwkk [ --FF_f_s ] [ ---- ] _p_r_o_g_r_a_m-_t_e_x_t file ...
  15.  
  16.      DESCRIPTION
  17.           _G_a_w_k is the GNU Project's implementation of the AWK
  18.           programming language.  It conforms to the definition and
  19.           description of the language 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,
  20.           by Aho, Kernighan, and Weinberger, with the additional
  21.           features defined in the System V Release 4 version of UNIX
  22.           _a_w_k.
  23.  
  24.           The command line consists of options to _g_a_w_k itself, the AWK
  25.           program text (if not supplied via the --ff option), and values
  26.           to be made available in the AARRGGCC and AARRGGVV pre-defined AWK
  27.           variables.
  28.  
  29.           The options that _g_a_w_k accepts are:
  30.  
  31.           --FF_f_s Use _f_s for the input field separator (the value of the
  32.                FFSS predefined variable). For compatibility with UNIX
  33.                _a_w_k, if _f_s is ``t'', then FFSS will be set to the tab
  34.                character.
  35.  
  36.           --ff _p_r_o_g_r_a_m-_f_i_l_e
  37.                Read the AWK program source from the file _p_r_o_g_r_a_m-_f_i_l_e,
  38.                instead of from the first command line argument.
  39.  
  40.           ----   Signal the end of options. This is useful to allow
  41.                further arguments to the AWK program itself to start
  42.                with a ``-''.  This is mainly for consistency with the
  43.                argument parsing convention used by most other System V
  44.                programs.
  45.  
  46.           Any other options are flagged as illegal, but are otherwise
  47.           ignored.  (However, see the GGNNUU EEXXTTEENNSSIIOONNSS section, below.)
  48.  
  49.           An AWK program consists of a sequence of pattern-action
  50.           statements and optional function definitions.
  51.  
  52.                _p_a_t_t_e_r_n   {{ _a_c_t_i_o_n _s_t_a_t_e_m_e_n_t_s }}
  53.                ffuunnccttiioonn _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 }}
  54.  
  55.           _G_a_w_k first reads the program source from the _p_r_o_g_r_a_m-_f_i_l_e(s)
  56.           if specified, or from the first non-option argument on the
  57.           command line.  The --ff option may be used multiple times on
  58.           the command line.  _G_a_w_k will read the program text as if all
  59.           the _p_r_o_g_r_a_m-_f_i_l_es had been concatenated together.  This is
  60.           useful for building libraries of AWK functions, without
  61.           having to include them in each new AWK program that uses
  62.           them.  To use a library function in a file from a program
  63.           typed in on the command line, specify //ddeevv//ttttyy as one of the
  64.           _p_r_o_g_r_a_m-_f_i_l_es, type your program, and end it with a ^^DD
  65.           (control-d).
  66.  
  67.  
  68.  
  69.      Page 1                                           (printed 4/6/89)
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  77.  
  78.  
  79.  
  80.           _G_a_w_k compiles the program into an internal form, and then
  81.           proceeds to read each file named in the AARRGGVV array.  If
  82.           there are no files named on the command line, _g_a_w_k reads the
  83.           standard input.
  84.  
  85.           If a ``file'' named on the command line has the form _v_a_r==_v_a_l
  86.           it is treated as a variable assignment. The variable _v_a_r
  87.           will be assigned the value _v_a_l.  This is most useful for
  88.           dynamically assigning values to the variables AWK uses to
  89.           control how input is broken into fields and records. It is
  90.           also useful for controlling state if multiple passes are
  91.           needed over a single data file.
  92.  
  93.           For each line in the input, _g_a_w_k tests to see if it matches
  94.           any _p_a_t_t_e_r_n in the AWK program.  For each pattern that the
  95.           line matches, the associated _a_c_t_i_o_n is executed.
  96.  
  97.      VARIABLES AND FIELDS
  98.           AWK variables are dynamic; they come into existence when
  99.           they are first used. Their values are either floating-point
  100.           numbers or strings, depending upon how they are used. AWK
  101.           also has single dimension arrays; multiply dimensioned
  102.           arrays may be simulated.  There are several pre-defined
  103.           variables that AWK sets as a program runs; these will be
  104.           described as needed and summarized below.
  105.  
  106.           As each input line is read, _g_a_w_k splits the line into
  107.           _f_i_e_l_d_s, using the value of the FFSS variable as the field
  108.           separator.  If FFSS is a single character, fields are
  109.           separated by that character.  Otherwise, FFSS is expected to
  110.           be a full regular expression.  In the special case that FFSS
  111.           is a single blank, fields are separated by runs of blanks
  112.           and/or tabs.
  113.  
  114.           Each field in the input line may be referenced by its
  115.           position, $$11, $$22, and so on.  $$00 is the whole line. The
  116.           value of a field may be assigned to as well.  Fields need
  117.           not be referenced by constants:
  118.  
  119.                nn == 55
  120.                pprriinntt $$nn
  121.  
  122.           prints the fifth field in the input line.  The variable NNFF
  123.           is set to the total number of fields in the input line.
  124.  
  125.           References to non-existent fields (i.e. fields after $$NNFF),
  126.           produce the null-string. However, assigning to a non-
  127.           existent field (e.g., $$((NNFF++22)) == 55) will increase the value
  128.           of NNFF, create any intervening fields with the null string as
  129.           their value, and cause the value of $$00 to be recomputed,
  130.           with the fields being separated by the value of OOFFSS.
  131.  
  132.         Built-in Variables
  133.           AWK's built-in variables are:
  134.  
  135.                AARRGGCC the number of command line arguments (does not
  136.                     include options to _g_a_w_k, or the program source).
  137.  
  138.  
  139.  
  140.  
  141.      Page 2                                           (printed 4/6/89)
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  149.  
  150.  
  151.  
  152.                AARRGGVV array of command line arguments. The array is
  153.                     indexed from 0 to AARRGGCC - 1.  Dynamically changing
  154.                     the contents of AARRGGVV can control the files used
  155.                     for data.
  156.  
  157.                EENNVVIIRROONN
  158.                     An array containing the values of the current
  159.                     environment.  The array is indexed by the
  160.                     environment variables, each element being the
  161.                     value of that variable (e.g., EENNVVIIRROONN[[""HHOOMMEE""]]
  162.                     might be //uu//aarrnnoolldd).  Changing this array does not
  163.                     affect the environment seen by programs which _g_a_w_k
  164.                     spawns via redirection or the ssyysstteemm function.
  165.  
  166.                FFIILLEENNAAMMEE
  167.                     the name of the current input file.  If no files
  168.                     are specified on the command line, the value of
  169.                     FFIILLEENNAAMMEE is ``-''.
  170.  
  171.                FFNNRR  the input record number in the current input file.
  172.  
  173.                FFSS   the input field separator, a blank by default.
  174.  
  175.                NNFF   the number of fields in the current input record.
  176.  
  177.                NNRR   the total number of input records seen so far.
  178.  
  179.                OOFFMMTT the output format for numbers, %%..66gg by default.
  180.  
  181.                OOFFSS  the output field separator, a blank by default.
  182.  
  183.                OORRSS  the output record separator, by default a newline.
  184.  
  185.                RRSS   the input record separator, by default a newline.
  186.                     RRSS is exceptional in that only the first character
  187.                     of its string value is used for separating
  188.                     records. If RRSS is set to the null string, then
  189.                     records are separated by blank lines.  When RRSS is
  190.                     set to the null string, then the newline character
  191.                     always acts as a field separator, in addition to
  192.                     whatever value FFSS may have.
  193.  
  194.                RRSSTTAARRTT
  195.                     the index of the first character matched by
  196.                     mmaattcchh(()); 0 if no match.
  197.  
  198.                RRLLEENNGGTTHH
  199.                     the length of the string matched by mmaattcchh(()); -1 if
  200.                     no match.
  201.  
  202.                SSUUBBSSEEPP
  203.                     the character used to separate multiple subscripts
  204.                     in array elements, by default ""\\003344"".
  205.  
  206.         Arrays
  207.           Arrays are subscripted with an expression between square
  208.           brackets ([[ and ]]).  If the expression is an expression list
  209.           (_e_x_p_r, _e_x_p_r ...) then the array subscript is a string
  210.  
  211.  
  212.  
  213.      Page 3                                           (printed 4/6/89)
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  221.  
  222.  
  223.  
  224.           consisting of the concatenation of the (string) value of
  225.           each expression, separated by the value of the SSUUBBSSEEPP
  226.           variable.  This facility is used to simulate multiply
  227.           dimensioned arrays. For example:
  228.  
  229.                ii == ""AA"" ;; jj == ""BB"" ;; kk == ""CC""
  230.                xx[[ii,,jj,,kk]] == ""hheelllloo,, wwoorrlldd\\nn""
  231.  
  232.           assigns the string ""hheelllloo,, wwoorrlldd\\nn"" to the element of the
  233.           array xx which is indexed by the string ""AA\\003344BB\\003344CC"". All
  234.           arrays in AWK are associative, i.e. indexed by string
  235.           values.
  236.  
  237.           The special operator iinn may be used in an iiff or wwhhiillee
  238.           statement to see if an array has an index consisting of a
  239.           particular value.
  240.  
  241.                iiff ((vvaall iinn aarrrraayy))
  242.                     pprriinntt aarrrraayy[[vvaall]]
  243.  
  244.           If the array has multiple subscripts, use ((ii,, jj)) iinn aarrrraayy.
  245.  
  246.           The iinn construct may also be used in a ffoorr loop to iterate
  247.           over all the elements of an array.
  248.  
  249.           An element may be deleted from an array using the ddeelleettee
  250.           statement.
  251.  
  252.         Variable Typing
  253.           Variables and fields may be (floating point) numbers, or
  254.           strings, or both. How the value of a variable is interpreted
  255.           depends upon its context. If used in a numeric expression,
  256.           it will be treated as a number, if used as a string it will
  257.           be treated as a string.
  258.  
  259.           To force a variable to be treated as a number, add 0 to it;
  260.           to force it to be treated as a string, concatenate it with
  261.           the null string.
  262.  
  263.           The AWK language defines comparisons as being done
  264.           numerically if possible, otherwise one or both operands are
  265.           converted to strings and a string comparison is performed.
  266.  
  267.           Uninitialized variables have the numeric value 0 and the
  268.           string value "" (the null, or empty, string).
  269.  
  270.      PATTERNS AND ACTIONS
  271.           AWK is a line oriented language. The pattern comes first,
  272.           and then the action. Action statements are enclosed in {{ and
  273.           }}.  Either the pattern may be missing, or the action may be
  274.           missing, but, of course, not both. If the pattern is
  275.           missing, the action will be executed for every single line
  276.           of input.  A missing action is equivalent to
  277.  
  278.                {{ pprriinntt }}
  279.  
  280.           which prints the entire line.
  281.  
  282.  
  283.  
  284.  
  285.      Page 4                                           (printed 4/6/89)
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  293.  
  294.  
  295.  
  296.           Comments begin with the ``#'' character, and continue until
  297.           the end of the line.  Blank lines may be used to separate
  298.           statements.  Normally, a statement ends with a newline,
  299.           however, this is not the case for lines ending in a ``,'',
  300.           ``{'', ``?'', ``:'', ``&&'', or ``||''.  Lines ending in ddoo
  301.           or eellssee also have their statements automatically continued
  302.           on the following line.  In other cases, a line can be
  303.           continued by ending it with a ``\'', in which case the
  304.           newline will be ignored.
  305.  
  306.           Multiple statements may be put on one line by separating
  307.           them with a ``;''.  This applies to both the statements
  308.           within the action part of a pattern-action pair (the usual
  309.           case), and to the pattern-action statements themselves.
  310.  
  311.         Patterns
  312.           AWK patterns may be one of the following:
  313.  
  314.                BBEEGGIINN
  315.                EENNDD
  316.                //_r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n//
  317.                _r_e_l_a_t_i_o_n_a_l _e_x_p_r_e_s_s_i_o_n
  318.                _p_a_t_t_e_r_n &&&& _p_a_t_t_e_r_n
  319.                _p_a_t_t_e_r_n |||| _p_a_t_t_e_r_n
  320.                _p_a_t_t_e_r_n ?? _p_a_t_t_e_r_n :: _p_a_t_t_e_r_n
  321.                ((_p_a_t_t_e_r_n))
  322.                !! _p_a_t_t_e_r_n
  323.                _p_a_t_t_e_r_n_1,, _p_a_t_t_e_r_n_2
  324.  
  325.           BBEEGGIINN and EENNDD are two special kinds of patterns which are
  326.           not tested against the input.  The action parts of all BBEEGGIINN
  327.           patterns are merged as if all the statements had been
  328.           written in a single BBEEGGIINN block. They are executed before
  329.           any of the input is read. Similarly, all the EENNDD blocks are
  330.           merged, and executed when all the input is exhausted (or
  331.           when an eexxiitt statement is executed).  BBEEGGIINN and EENNDD patterns
  332.           cannot be combined with other patterns in pattern
  333.           expressions.  BBEEGGIINN and EENNDD patterns cannot have missing
  334.           action parts.
  335.  
  336.           For //_r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n// patterns, the associated statement
  337.           is executed for each input line that matches the regular
  338.           expression.  Regular expressions are the same as those in
  339.           _e_g_r_e_p(1), and are summarized below.
  340.  
  341.           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
  342.           below in the section on actions.  These generally test
  343.           whether certain fields match certain regular expressions.
  344.  
  345.           The &&&&, ||||, and !! operators are logical AND, logical OR, and
  346.           logical NOT, respectively, as in C.  They do short-circuit
  347.           evaluation, also as in C, and are used for combining more
  348.           primitive pattern expressions. As in most languages,
  349.           parentheses may be used to change the order of evaluation.
  350.  
  351.           The ??:: operator is like the same operator in C. If the first
  352.           pattern is true then the pattern used for testing is the
  353.           second pattern, otherwise it is the third. Only one of the
  354.  
  355.  
  356.  
  357.      Page 5                                           (printed 4/6/89)
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  365.  
  366.  
  367.  
  368.           second and third patterns is evaluated.
  369.  
  370.           The _p_a_t_t_e_r_n_1,, _p_a_t_t_e_r_n_2 form of an expression is called a
  371.           range pattern.  It matches all input lines starting with a
  372.           line that matches _p_a_t_t_e_r_n_1, and continuing until a line that
  373.           matches _p_a_t_t_e_r_n_2, inclusive. It does not combine with any
  374.           other sort of pattern expression.
  375.  
  376.         Regular Expressions
  377.           Regular expressions are the extended kind found in _e_g_r_e_p.
  378.           They are composed of characters as follows:
  379.  
  380.                _c    matches the non-metacharacter _c.
  381.  
  382.                _\_c   matches the literal character _c.
  383.  
  384.                ..    matches any character except newline.
  385.  
  386.                ^^    matches the beginning of a line or a string.
  387.  
  388.                $$    matches the end of a line or a string.
  389.  
  390.                [[_a_b_c...]]
  391.                     character class, matches any of the characters
  392.                     _a_b_c....
  393.  
  394.                [[^^_a_b_c...]]
  395.                     negated character class, matches any character
  396.                     except _a_b_c... and newline.
  397.  
  398.                _r_1||_r_2
  399.                     alternation: matches either _r_1 or _r_2.
  400.  
  401.                _r_1_r_2 concatenation: matches _r_1, and then _r_2.
  402.  
  403.                _r++   matches one or more _r's.
  404.  
  405.                _r**   matches zero or more _r's.
  406.  
  407.                _r??   matches zero or one _r's.
  408.  
  409.                ((_r))  grouping: matches _r.
  410.  
  411.         Actions
  412.           Action statements are enclosed in braces, {{ and }}.  Action
  413.           statements consist of the usual assignment, conditional, and
  414.           looping statements found in most languages. The operators,
  415.           control statements, and input/output statements available
  416.           are patterned after those in C.
  417.  
  418.           The operators in AWK, in order of increasing precedence, are
  419.  
  420.                == ++== --== **== //== %%== ^^==
  421.                     Assignment. Both absolute assignment ((_v_a_r == _v_a_l_u_e))
  422.                     and operator-assignment (the other forms) are
  423.                     supported.
  424.  
  425.                ??::   The C conditional expression. This has the form
  426.  
  427.  
  428.  
  429.      Page 6                                           (printed 4/6/89)
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  437.  
  438.  
  439.  
  440.                     _e_x_p_r_1 ?? _e_x_p_r_2 :: _e_x_p_r_3. If _e_x_p_r_1 is true, the value
  441.                     of the expression is _e_x_p_r_2, otherwise it is _e_x_p_r_3.
  442.                     Only one of _e_x_p_r_2 and _e_x_p_r_3 is evaluated.
  443.  
  444.                ||||   logical OR.
  445.  
  446.                &&&&   logical AND.
  447.  
  448.                ~~ !!~~ regular expression match, negated match.
  449.  
  450.                << <<== >> >>== !!== ====
  451.                     the regular relational operators.
  452.  
  453.                _b_l_a_n_k
  454.                     string concatenation.
  455.  
  456.                ++ --  addition and subtraction.
  457.  
  458.                ** // %%
  459.                     multiplication, division, and modulus.
  460.  
  461.                ++ -- !!
  462.                     unary plus, unary minus, and logical negation.
  463.  
  464.                ^^    exponentiation (**** may also be used, and ****== for
  465.                     the assignment operator).
  466.  
  467.                ++++ ----
  468.                     increment and decrement, both prefix and postfix.
  469.  
  470.                $$    field reference.
  471.  
  472.           The control statements are as follows:
  473.  
  474.                iiff ((_c_o_n_d_i_t_i_o_n)) _s_t_a_t_e_m_e_n_t [ eellssee _s_t_a_t_e_m_e_n_t ]
  475.                wwhhiillee ((_c_o_n_d_i_t_i_o_n)) _s_t_a_t_e_m_e_n_t
  476.                ddoo _s_t_a_t_e_m_e_n_t wwhhiillee ((_c_o_n_d_i_t_i_o_n))
  477.                ffoorr ((_e_x_p_r_1;; _e_x_p_r_2;; _e_x_p_r_3)) _s_t_a_t_e_m_e_n_t
  478.                ffoorr ((_v_a_r iinn _a_r_r_a_y)) _s_t_a_t_e_m_e_n_t
  479.                bbrreeaakk
  480.                ccoonnttiinnuuee
  481.                ddeelleettee _a_r_r_a_y[[_i_n_d_e_x]]
  482.                eexxiitt [ _e_x_p_r_e_s_s_i_o_n ]
  483.                {{ _s_t_a_t_e_m_e_n_t_s }}
  484.  
  485.           The input/output statements are as follows:
  486.  
  487.                cclloossee((_f_i_l_e_n_a_m_e))
  488.                     close file (or pipe, see below).
  489.  
  490.                ggeettlliinnee
  491.                     set $$00 from next input record; set NNFF, NNRR, FFNNRR.
  492.  
  493.                ggeettlliinnee <<_f_i_l_e
  494.                     set $$00 from next record of _f_i_l_e; set NNFF.
  495.  
  496.                ggeettlliinnee _v_a_r
  497.                     set _v_a_r from next input record; set NNFF, FFNNRR.
  498.  
  499.  
  500.  
  501.      Page 7                                           (printed 4/6/89)
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  509.  
  510.  
  511.  
  512.                ggeettlliinnee _v_a_r <<_f_i_l_e
  513.                     set _v_a_r from next record of _f_i_l_e.
  514.  
  515.                nneexxtt Stop processing the current input record. The next
  516.                     input record is read and processing starts over
  517.                     with the first pattern in the AWK program. If the
  518.                     end of the input data is reached, the EENNDD
  519.                     block(s), if any, are executed.
  520.  
  521.                pprriinntt
  522.                     prints the current record.
  523.  
  524.                pprriinntt _e_x_p_r-_l_i_s_t
  525.                     prints expressions.
  526.  
  527.                pprriinntt _e_x_p_r-_l_i_s_t >>_f_i_l_e
  528.                     prints expressions on _f_i_l_e.
  529.  
  530.                pprriinnttff _f_m_t, _e_x_p_r-_l_i_s_t
  531.                     format and print.
  532.  
  533.                pprriinnttff _f_m_t, _e_x_p_r-_l_i_s_t >>_f_i_l_e
  534.                     format and print on _f_i_l_e.
  535.  
  536.                ssyysstteemm((_c_m_d-_l_i_n_e))
  537.                     execute the command _c_m_d-_l_i_n_e, and return the exit
  538.                     status.  (This may not be available on systems
  539.                     besides UNIX and GNU.)
  540.  
  541.           Other input/output redirections are also allowed. For pprriinntt
  542.           and pprriinnttff, >>>>_f_i_l_e appends output to the _f_i_l_e, while ||
  543.           _c_o_m_m_a_n_d writes on a pipe.  In a similar fashion, _c_o_m_m_a_n_d ||
  544.           ggeettlliinnee pipes into ggeettlliinnee.  GGeettlliinnee will return 0 on end of
  545.           file, and -1 on an error.
  546.  
  547.           The AWK versions of the pprriinnttff and sspprriinnttff (see below)
  548.           functions accept the following conversion specification
  549.           formats:
  550.  
  551.                %%cc   An ASCII character.
  552.  
  553.                %%dd   A decimal number (the integer part).
  554.  
  555.                %%ee   A floating point number of the form
  556.                     [[--]]dd..ddddddddddddEE[[++--]]dddd.
  557.  
  558.                %%ff   A floating point number of the form [[--]]dddddd..dddddddddddd.
  559.  
  560.                %%gg   Use ee or ff conversion, whichever is shorter, with
  561.                     nonsignificant zeros suppressed.
  562.  
  563.                %%oo   An unsigned octal number (again, an integer).
  564.  
  565.                %%ss   A character string.
  566.  
  567.                %%xx   An unsigned hexadecimal number (an integer).
  568.  
  569.                %%%%   A single %% character; no argument is converted.
  570.  
  571.  
  572.  
  573.      Page 8                                           (printed 4/6/89)
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  581.  
  582.  
  583.  
  584.           There are optional, additional parameters that may lie
  585.           between the %% and the control letter:
  586.  
  587.                --    The expression should be left-justified within its
  588.                     field.
  589.  
  590.                _w_i_d_t_h
  591.                     The field should be padded to this width. If the
  592.                     number has a leading zero, then the field will be
  593.                     padded with zeros.  Otherwise it is padded with
  594.                     blanks.
  595.  
  596.                .._p_r_e_c
  597.                     A number indicating the maximum width of strings
  598.                     or digits to the right of the decimal point.
  599.  
  600.           The dynamic _w_i_d_t_h and _p_r_e_c capabilities of the C library
  601.           pprriinnttff routines are not supported.  However, they may be
  602.           simulated by using the AWK concatenation operation to build
  603.           up a format specification dynamically.
  604.  
  605.           AWK has the following pre-defined arithmetic functions:
  606.  
  607.                aattaann22((_y,, _x))
  608.                     returns the arctangent of _y/_x in radians.
  609.  
  610.                ccooss((_e_x_p_r))
  611.                     returns the cosine in radians.
  612.  
  613.                eexxpp((_e_x_p_r))
  614.                     the exponential function.
  615.  
  616.                iinntt((_e_x_p_r))
  617.                     truncates to integer.
  618.  
  619.                lloogg((_e_x_p_r))
  620.                     the natural logarithm function.
  621.  
  622.                rraanndd(())
  623.                     returns a random number between 0 and 1.
  624.  
  625.                ssiinn((_e_x_p_r))
  626.                     returns the sine in radians.
  627.  
  628.                ssqqrrtt((_e_x_p_r))
  629.                     the square root function.
  630.  
  631.                ssrraanndd((_e_x_p_r))
  632.                     use _e_x_p_r as a new seed for the random number
  633.                     generator. If no _e_x_p_r is provided, the time of day
  634.                     will be used.  The return value is the previous
  635.                     seed for the random number generator.
  636.  
  637.           AWK has the following pre-defined string functions:
  638.  
  639.                ggssuubb((_r,, _s,, _t))
  640.                     for each substring matching the regular expression
  641.                     _r in the string _t, substitute the string _s, and
  642.  
  643.  
  644.  
  645.      Page 9                                           (printed 4/6/89)
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  653.  
  654.  
  655.  
  656.                     return the number of substitutions.  If _t is not
  657.                     supplied, use $$00.
  658.  
  659.                iinnddeexx((_s,, _t))
  660.                     returns the index of the string _t in the string _s,
  661.                     or 0 if _t is not present.
  662.  
  663.                lleennggtthh((_s))
  664.                     returns the length of the string _s.
  665.  
  666.                mmaattcchh((_s,, _r))
  667.                     returns the position in _s where the regular
  668.                     expression _r occurs, or 0 if _r is not present, and
  669.                     sets the values of RRSSTTAARRTT and RRLLEENNGGTTHH.
  670.  
  671.                sspplliitt((_s,, _a,, _r))
  672.                     splits the string _s into the array _a on the
  673.                     regular expression _r, and returns the number of
  674.                     fields. If _r is omitted, FFSS is used instead.
  675.  
  676.                sspprriinnttff((_f_m_t,, _e_x_p_r-_l_i_s_t))
  677.                     prints _e_x_p_r-_l_i_s_t according to _f_m_t, and returns the
  678.                     resulting string.
  679.  
  680.                ssuubb((_r,, _s,, _t))
  681.                     this is just like ggssuubb, but only the first
  682.                     matching substring is replaced.
  683.  
  684.                ssuubbssttrr((_s,, _i,, _n))
  685.                     returns the _n-character substring of _s starting at
  686.                     _i.  If _n is omitted, the rest of _s is used.
  687.  
  688.           String constants in AWK are sequences of characters enclosed
  689.           between double quotes (""). Within strings, certain _e_s_c_a_p_e
  690.           _s_e_q_u_e_n_c_e_s are recognized, as in C. These are:
  691.  
  692.                \\bb   backspace.
  693.  
  694.                \\ff   form-feed.
  695.  
  696.                \\nn   new line.
  697.  
  698.                \\rr   carriage return.
  699.  
  700.                \\tt   horizontal tab.
  701.  
  702.                \\vv   vertical tab.
  703.  
  704.                \\_d_d_d The character represented by the 1-, 2-, or 3-
  705.                     digit sequence of octal digits. E.g. "\033" is the
  706.                     ASCII ESC (escape) character.
  707.  
  708.      FUNCTIONS
  709.           Functions in AWK are defined as follows:
  710.  
  711.                ffuunnccttiioonn _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 }}
  712.  
  713.           Functions are executed when called from within the action
  714.  
  715.  
  716.  
  717.      Page 10                                          (printed 4/6/89)
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  725.  
  726.  
  727.  
  728.           parts of regular pattern-action statements. Actual
  729.           parameters supplied in the function call are used to
  730.           instantiate the formal parameters declared in the function.
  731.           Arrays are passed by reference, other variables are passed
  732.           by value.
  733.  
  734.           Since functions were not originally part of the AWK
  735.           language, the provision for local variables is rather
  736.           clumsy: they are declared as extra parameters in the
  737.           parameter list. The convention is to separate local
  738.           variables from real parameters by extra spaces in the
  739.           parameter list. For example:
  740.  
  741.                ffuunnccttiioonn  ff((pp,, qq,,     aa,, bb)) {{ ## aa && bb aarree llooccaall
  742.                               .......... }}
  743.  
  744.                //aabbcc//     {{ ...... ;; ff((11,, 22)) ;; ...... }}
  745.  
  746.           The left parenthesis in a function call is required to
  747.           immediately follow the function name, without any
  748.           intervening white space.  This is to avoid a syntactic
  749.           ambiguity with the concatenation operator.  This restriction
  750.           does not apply to the built-in functions listed above.
  751.  
  752.           Functions may call each other and may be recursive.
  753.           Function parameters used as local variables are initialized
  754.           to the null string and the number zero upon function
  755.           invocation.
  756.  
  757.           The word ffuunncc may be used in place of ffuunnccttiioonn.
  758.  
  759.      EXAMPLES
  760.           Print and sort the login names of all users:
  761.  
  762.                BBEEGGIINN     {{ FFSS == ""::"" }}
  763.                     {{ pprriinntt $$11 || ""ssoorrtt"" }}
  764.  
  765.           Count lines in a file:
  766.  
  767.                     {{ nnlliinneess++++ }}
  768.                EENNDD  {{ pprriinntt nnlliinneess }}
  769.  
  770.           Precede each line by its number in the file:
  771.  
  772.                {{ pprriinntt FFNNRR,, $$00 }}
  773.  
  774.           Concatenate and line number (a variation on a theme):
  775.  
  776.                {{ pprriinntt NNRR,, $$00 }}
  777.  
  778.      SEE ALSO
  779.           _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.
  780.           Kernighan, Peter J. Weinberger, Addison-Wesley, 1988. ISBN
  781.           0-201-07981-X.
  782.  
  783.      SYSTEM V RELEASE 4 COMPATIBILITY
  784.           A primary goal for _g_a_w_k is compatibility with the latest
  785.           version of UNIX _a_w_k.  To this end, _g_a_w_k incorporates the
  786.  
  787.  
  788.  
  789.      Page 11                                          (printed 4/6/89)
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  797.  
  798.  
  799.  
  800.           following user visible features which are not described in
  801.           the AWK book, but are part of _a_w_k in System V Release 4.
  802.  
  803.           When processing arguments, _g_a_w_k uses the special option
  804.           ``----'' to signal the end of arguments, and warns about, but
  805.           otherwise ignores, undefined options.
  806.  
  807.           The AWK book does not define the return value of ssrraanndd(()).
  808.           The System V Release 4 version of UNIX _a_w_k has it return the
  809.           seed it was using, to allow keeping track of random number
  810.           sequences. Therefore ssrraanndd(()) in _g_a_w_k also returns its
  811.           current seed.
  812.  
  813.           The use of multiple --ff options is a new feature, as is the
  814.           EENNVVIIRROONN array.
  815.  
  816.      GNU EXTENSIONS
  817.           _G_a_w_k has some extensions to System V _a_w_k.  They are
  818.           described in this section.  All features described in this
  819.           section may change at some time in the future, or may go
  820.           away entirely.  They can be disabled either by compiling
  821.           _g_a_w_k with --DDSSTTRRIICCTT, or by invoking _g_a_w_k with the name _a_w_k.
  822.           You should not write programs that depend upon them.
  823.  
  824.           The environment variable AAWWKKPPAATTHH specifies a search path to
  825.           use when finding source files named with the --ff option.  If
  826.           this variable does not exist, the default path is
  827.           ""..:://uussrr//lliibb//aawwkk:://uussrr//llooccaall//lliibb//aawwkk"".  If a file name given
  828.           to the --ff option contains a ``/'' character, no path search
  829.           is performed.
  830.  
  831.           Two new relational operators are defined, ~~~~, and !!~~~~.
  832.           These perform case independent regular expression match and
  833.           no-match operations, respectively.
  834.  
  835.           The AWK book does not define the return value of the cclloossee
  836.           function.  _G_a_w_k's cclloossee returns the value from _f_c_l_o_s_e(3), or
  837.           _p_c_l_o_s_e(3), when closing a file or pipe, respectively.
  838.  
  839.           _G_a_w_k accepts the following additional arguments:
  840.  
  841.           --ii   Ignore case when doing regular expression operations.
  842.                This causes ~~ and !!~~ to behave like the new operators
  843.                ~~~~ and !!~~~~, described above.
  844.  
  845.           --vv   Print version information for this particular copy of
  846.                _g_a_w_k on the error output.  This is useful mainly for
  847.                knowing if the current copy of _g_a_w_k on your system is
  848.                up to date with respect to whatever the Free Software
  849.                Foundation is distributing.
  850.  
  851.      BUGS
  852.           The --FF option is not necessary given the command line
  853.           variable assignment feature; it remains only for backwards
  854.           compatibility.
  855.  
  856.      AUTHORS
  857.           The original version of UNIX _a_w_k was designed and
  858.  
  859.  
  860.  
  861.      Page 12                                          (printed 4/6/89)
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.      GAWK(1)     OS9/68000 V2.1 (Free Software Foundation)     GAWK(1)
  869.  
  870.  
  871.  
  872.           implemented by Alfred Aho, Peter Weinberger, and Brian
  873.           Kernighan of AT&T Bell Labs. Brian Kernighan continues to
  874.           maintain and enhance it.
  875.  
  876.           Paul Rubin and Jay Fenlason, with John Woods, all of the
  877.           Free Software Foundation, wrote _g_a_w_k, to be compatible with
  878.           the original version of _a_w_k distributed in Seventh Edition
  879.           UNIX.  David Trueman of Dalhousie University, with
  880.           contributions from Arnold Robbins at Emory University, made
  881.           _g_a_w_k compatible with the new version of UNIX _a_w_k.
  882.  
  883.      ACKNOWLEDGEMENTS
  884.           Brian Kernighan of Bell Labs provided valuable assistance
  885.           during testing and debugging.  We thank him.
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.  
  932.  
  933.      Page 13                                          (printed 4/6/89)
  934.  
  935.  
  936.  
  937.