AWK(1)                     POSIX Programmer's Manual                    AWK(1)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       awk -- pattern scanning and processing language

SSYYNNOOPPSSIISS
       awk [[-F _s_e_p_s_t_r_i_n_g]] [[-v _a_s_s_i_g_n_m_e_n_t]]... _p_r_o_g_r_a_m [[_a_r_g_u_m_e_n_t...]]

       awk [[-F _s_e_p_s_t_r_i_n_g]] -f _p_r_o_g_f_i_l_e [[-f _p_r_o_g_f_i_l_e]]... [[-v _a_s_s_i_g_n_m_e_n_t]]...
            [[_a_r_g_u_m_e_n_t...]]

DDEESSCCRRIIPPTTIIOONN
       The _a_w_k utility shall execute programs written in the _a_w_k programming
       language, which is specialized for textual data manipulation. An _a_w_k
       program is a sequence of patterns and corresponding actions. When input
       is read that matches a pattern, the action associated with that pattern
       is carried out.

       Input shall be interpreted as a sequence of records. By default, a
       record is a line, less its terminating <newline>, but this can be
       changed by using the RRSS built-in variable. Each record of input shall
       be matched in turn against each pattern in the program. For each
       pattern matched, the associated action shall be executed.

       The _a_w_k utility shall interpret each input record as a sequence of
       fields where, by default, a field is a string of non-<blank>
       non-<newline> characters. This default <blank> and <newline> field
       delimiter can be changed by using the FFSS built-in variable or the --FF
       _s_e_p_s_t_r_i_n_g option. The _a_w_k utility shall denote the first field in a
       record $1, the second $2, and so on. The symbol $0 shall refer to the
       entire record; setting any other field causes the re-evaluation of $0.
       Assigning to $0 shall reset the values of all other fields and the NNFF
       built-in variable.

OOPPTTIIOONNSS
       The _a_w_k utility shall conform to the Base Definitions volume of
       POSIX.1-2017, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s.

       The following options shall be supported:

       --FF _s_e_p_s_t_r_i_n_g
                 Define the input field separator. This option shall be
                 equivalent to:


                     -v FS=_s_e_p_s_t_r_i_n_g

                 except that if --FF _s_e_p_s_t_r_i_n_g and --vv FS=_s_e_p_s_t_r_i_n_g are both
                 used, it is unspecified whether the FFSS assignment resulting
                 from --FF _s_e_p_s_t_r_i_n_g is processed in command line order or is
                 processed after the last --vv FS=_s_e_p_s_t_r_i_n_g.  See the
                 description of the FFSS built-in variable, and how it is used,
                 in the EXTENDED DESCRIPTION section.

       --ff _p_r_o_g_f_i_l_e
                 Specify the pathname of the file _p_r_o_g_f_i_l_e containing an _a_w_k
                 program. A pathname of ''--'' shall denote the standard input.
                 If multiple instances of this option are specified, the
                 concatenation of the files specified as _p_r_o_g_f_i_l_e in the order
                 specified shall be the _a_w_k program. The _a_w_k program can
                 alternatively be specified in the command line as a single
                 argument.

       --vv _a_s_s_i_g_n_m_e_n_t
                 The application shall ensure that the _a_s_s_i_g_n_m_e_n_t argument is
                 in the same form as an _a_s_s_i_g_n_m_e_n_t operand. The specified
                 variable assignment shall occur prior to executing the _a_w_k
                 program, including the actions associated with BBEEGGIINN patterns
                 (if any). Multiple occurrences of this option can be
                 specified.

OOPPEERRAANNDDSS
       The following operands shall be supported:

       _p_r_o_g_r_a_m   If no --ff option is specified, the first operand to _a_w_k shall
                 be the text of the _a_w_k program. The application shall supply
                 the _p_r_o_g_r_a_m operand as a single argument to _a_w_k.  If the text
                 does not end in a <newline>, _a_w_k shall interpret the text as
                 if it did.

       _a_r_g_u_m_e_n_t  Either of the following two types of _a_r_g_u_m_e_n_t can be
                 intermixed:

                 _f_i_l_e      A pathname of a file that contains the input to be
                           read, which is matched against the set of patterns
                           in the program. If no _f_i_l_e operands are specified,
                           or if a _f_i_l_e operand is ''--'', the standard input
                           shall be used.

                 _a_s_s_i_g_n_m_e_n_t
                           An operand that begins with an <underscore> or
                           alphabetic character from the portable character
                           set (see the table in the Base Definitions volume
                           of POSIX.1-2017, _S_e_c_t_i_o_n _6_._1, _P_o_r_t_a_b_l_e _C_h_a_r_a_c_t_e_r
                           _S_e_t), followed by a sequence of underscores,
                           digits, and alphabetics from the portable character
                           set, followed by the ''=='' character, shall specify a
                           variable assignment rather than a pathname.  The
                           characters before the ''=='' represent the name of an
                           _a_w_k variable; if that name is an _a_w_k reserved word
                           (see _G_r_a_m_m_a_r) the behavior is undefined. The
                           characters following the <equals-sign> shall be
                           interpreted as if they appeared in the _a_w_k program
                           preceded and followed by a double-quote (''""'')
                           character, as a SSTTRRIINNGG token (see _G_r_a_m_m_a_r), except
                           that if the last character is an unescaped
                           <backslash>, it shall be interpreted as a literal
                           <backslash> rather than as the first character of
                           the sequence ""\\"""".  The variable shall be assigned
                           the value of that SSTTRRIINNGG token and, if appropriate,
                           shall be considered a _n_u_m_e_r_i_c _s_t_r_i_n_g (see
                           _E_x_p_r_e_s_s_i_o_n_s _i_n _a_w_k), the variable shall also be
                           assigned its numeric value. Each such variable
                           assignment shall occur just prior to the processing
                           of the following _f_i_l_e, if any. Thus, an assignment
                           before the first _f_i_l_e argument shall be executed
                           after the BBEEGGIINN actions (if any), while an
                           assignment after the last _f_i_l_e argument shall occur
                           before the EENNDD actions (if any). If there are no
                           _f_i_l_e arguments, assignments shall be executed
                           before processing the standard input.

SSTTDDIINN
       The standard input shall be used only if no _f_i_l_e operands are
       specified, or if a _f_i_l_e operand is ''--'', or if a _p_r_o_g_f_i_l_e option-
       argument is ''--''; see the INPUT FILES section. If the _a_w_k program
       contains no actions and no patterns, but is otherwise a valid _a_w_k
       program, standard input and any _f_i_l_e operands shall not be read and _a_w_k
       shall exit with a return status of zero.

IINNPPUUTT FFIILLEESS
       Input files to the _a_w_k program from any of the following sources shall
       be text files:

        *  Any _f_i_l_e operands or their equivalents, achieved by modifying the
           _a_w_k variables AARRGGVV and AARRGGCC

        *  Standard input in the absence of any _f_i_l_e operands

        *  Arguments to the ggeettlliinnee function

       Whether the variable RRSS is set to a value other than a <newline> or
       not, for these files, implementations shall support records terminated
       with the specified separator up to {LINE_MAX} bytes and may support
       longer records.

       If --ff _p_r_o_g_f_i_l_e is specified, the application shall ensure that the
       files named by each of the _p_r_o_g_f_i_l_e option-arguments are text files and
       their concatenation, in the same order as they appear in the arguments,
       is an _a_w_k program.

EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
       The following environment variables shall affect the execution of _a_w_k:

       _L_A_N_G      Provide a default value for the internationalization
                 variables that are unset or null. (See the Base Definitions
                 volume of POSIX.1-2017, _S_e_c_t_i_o_n _8_._2, _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n
                 _V_a_r_i_a_b_l_e_s for the precedence of internationalization
                 variables used to determine the values of locale categories.)

       _L_C___A_L_L    If set to a non-empty string value, override the values of
                 all the other internationalization variables.

       _L_C___C_O_L_L_A_T_E
                 Determine the locale for the behavior of ranges, equivalence
                 classes, and multi-character collating elements within
                 regular expressions and in comparisons of string values.

       _L_C___C_T_Y_P_E  Determine the locale for the interpretation of sequences of
                 bytes of text data as characters (for example, single-byte as
                 opposed to multi-byte characters in arguments and input
                 files), the behavior of character classes within regular
                 expressions, the identification of characters as letters, and
                 the mapping of uppercase and lowercase characters for the
                 ttoouuppppeerr and ttoolloowweerr functions.

       _L_C___M_E_S_S_A_G_E_S
                 Determine the locale that should be used to affect the format
                 and contents of diagnostic messages written to standard
                 error.

       _L_C___N_U_M_E_R_I_C
                 Determine the radix character used when interpreting numeric
                 input, performing conversions between numeric and string
                 values, and formatting numeric output. Regardless of locale,
                 the <period> character (the decimal-point character of the
                 POSIX locale) is the decimal-point character recognized in
                 processing _a_w_k programs (including assignments in command
                 line arguments).

       _N_L_S_P_A_T_H   Determine the location of message catalogs for the processing
                 of _L_C___M_E_S_S_A_G_E_S.

       _P_A_T_H      Determine the search path when looking for commands executed
                 by _s_y_s_t_e_m(_e_x_p_r), or input and output pipes; see the Base
                 Definitions volume of POSIX.1-2017, _C_h_a_p_t_e_r _8, _E_n_v_i_r_o_n_m_e_n_t
                 _V_a_r_i_a_b_l_e_s.

       In addition, all environment variables shall be visible via the _a_w_k
       variable EENNVVIIRROONN.

AASSYYNNCCHHRROONNOOUUSS EEVVEENNTTSS
       Default.

SSTTDDOOUUTT
       The nature of the output files depends on the _a_w_k program.

SSTTDDEERRRR
       The standard error shall be used only for diagnostic messages.

OOUUTTPPUUTT FFIILLEESS
       The nature of the output files depends on the _a_w_k program.

EEXXTTEENNDDEEDD DDEESSCCRRIIPPTTIIOONN
   OOvveerraallll PPrrooggrraamm SSttrruuccttuurree
       An _a_w_k program is composed of pairs of the form:


           _p_a_t_t_e_r_n { _a_c_t_i_o_n }

       Either the pattern or the action (including the enclosing brace
       characters) can be omitted.

       A missing pattern shall match any record of input, and a missing action
       shall be equivalent to:


           { print }

       Execution of the _a_w_k program shall start by first executing the actions
       associated with all BBEEGGIINN patterns in the order they occur in the
       program. Then each _f_i_l_e operand (or standard input if no files were
       specified) shall be processed in turn by reading data from the file
       until a record separator is seen (<newline> by default). Before the
       first reference to a field in the record is evaluated, the record shall
       be split into fields, according to the rules in _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s,
       using the value of FFSS that was current at the time the record was read.
       Each pattern in the program then shall be evaluated in the order of
       occurrence, and the action associated with each pattern that matches
       the current record executed. The action for a matching pattern shall be
       executed before evaluating subsequent patterns. Finally, the actions
       associated with all EENNDD patterns shall be executed in the order they
       occur in the program.

   EExxpprreessssiioonnss iinn aawwkk
       Expressions describe computations used in _p_a_t_t_e_r_n_s and _a_c_t_i_o_n_s.  In the
       following table, valid expression operations are given in groups from
       highest precedence first to lowest precedence last, with equal-
       precedence operators grouped between horizontal lines. In expression
       evaluation, where the grammar is formally ambiguous, higher precedence
       operators shall be evaluated before lower precedence operators. In this
       table _e_x_p_r, _e_x_p_r_1, _e_x_p_r_2, and _e_x_p_r_3 represent any expression, while
       lvalue represents any entity that can be assigned to (that is, on the
       left side of an assignment operator).  The precise syntax of
       expressions is given in _G_r_a_m_m_a_r.

               TTaabbllee 44--11:: EExxpprreessssiioonnss iinn DDeeccrreeaassiinngg PPrreecceeddeennccee iinn _a_w_k

   +---------------------+-------------------------+----------------+--------------+
   |       SSyynnttaaxx        |          NNaammee           | TTyyppee ooff RReessuulltt |AAssssoocciiaattiivviittyy |
   +---------------------+-------------------------+----------------+--------------+
   |( _e_x_p_r )             |Grouping                 |Type of _e_x_p_r    |N/A           |
   +---------------------+-------------------------+----------------+--------------+
   |$_e_x_p_r                |Field reference          |String          |N/A           |
   +---------------------+-------------------------+----------------+--------------+
   |lvalue ++            |Post-increment           |Numeric         |N/A           |
   |lvalue --            |Post-decrement           |Numeric         |N/A           |
   +---------------------+-------------------------+----------------+--------------+
   |++ lvalue            |Pre-increment            |Numeric         |N/A           |
   |-- lvalue            |Pre-decrement            |Numeric         |N/A           |
   +---------------------+-------------------------+----------------+--------------+
   |_e_x_p_r ^ _e_x_p_r          |Exponentiation           |Numeric         |Right         |
   +---------------------+-------------------------+----------------+--------------+
   |! _e_x_p_r               |Logical not              |Numeric         |N/A           |
   |+ _e_x_p_r               |Unary plus               |Numeric         |N/A           |
   |- _e_x_p_r               |Unary minus              |Numeric         |N/A           |
   +---------------------+-------------------------+----------------+--------------+
   |_e_x_p_r * _e_x_p_r          |Multiplication           |Numeric         |Left          |
   |_e_x_p_r / _e_x_p_r          |Division                 |Numeric         |Left          |
   |_e_x_p_r % _e_x_p_r          |Modulus                  |Numeric         |Left          |
   +---------------------+-------------------------+----------------+--------------+
   |_e_x_p_r + _e_x_p_r          |Addition                 |Numeric         |Left          |
   |_e_x_p_r - _e_x_p_r          |Subtraction              |Numeric         |Left          |
   +---------------------+-------------------------+----------------+--------------+
   |_e_x_p_r _e_x_p_r            |String concatenation     |String          |Left          |
   +---------------------+-------------------------+----------------+--------------+
   |_e_x_p_r < _e_x_p_r          |Less than                |Numeric         |None          |
   |_e_x_p_r <= _e_x_p_r         |Less than or equal to    |Numeric         |None          |
   |_e_x_p_r != _e_x_p_r         |Not equal to             |Numeric         |None          |
   |_e_x_p_r == _e_x_p_r         |Equal to                 |Numeric         |None          |
   |_e_x_p_r > _e_x_p_r          |Greater than             |Numeric         |None          |
   |_e_x_p_r >= _e_x_p_r         |Greater than or equal to |Numeric         |None          |
   +---------------------+-------------------------+----------------+--------------+
   |_e_x_p_r ~ _e_x_p_r          |ERE match                |Numeric         |None          |
   |_e_x_p_r !~ _e_x_p_r         |ERE non-match            |Numeric         |None          |
   +---------------------+-------------------------+----------------+--------------+
   |_e_x_p_r in array        |Array membership         |Numeric         |Left          |
   |( _i_n_d_e_x ) in _a_r_r_a_y   |Multi-dimension array    |Numeric         |Left          |
   |                     |membership               |                |              |
   +---------------------+-------------------------+----------------+--------------+
   |_e_x_p_r && _e_x_p_r         |Logical AND              |Numeric         |Left          |
   +---------------------+-------------------------+----------------+--------------+
   |_e_x_p_r || _e_x_p_r         |Logical OR               |Numeric         |Left          |
   +---------------------+-------------------------+----------------+--------------+
   |_e_x_p_r_1 ? _e_x_p_r_2 : _e_x_p_r_3|Conditional expression   |Type of selected|Right         |
   |                     |                         |_e_x_p_r_2 or _e_x_p_r_3  |              |
   +---------------------+-------------------------+----------------+--------------+
   |lvalue ^= _e_x_p_r       |Exponentiation assignment|Numeric         |Right         |
   |lvalue %= _e_x_p_r       |Modulus assignment       |Numeric         |Right         |
   |lvalue *= _e_x_p_r       |Multiplication assignment|Numeric         |Right         |
   |lvalue /= _e_x_p_r       |Division assignment      |Numeric         |Right         |
   |lvalue += _e_x_p_r       |Addition assignment      |Numeric         |Right         |
   |lvalue -= _e_x_p_r       |Subtraction assignment   |Numeric         |Right         |
   |lvalue = _e_x_p_r        |Assignment               |Type of _e_x_p_r    |Right         |
   +---------------------+-------------------------+----------------+--------------+
       Each expression shall have either a string value, a numeric value, or
       both. Except as stated for specific contexts, the value of an
       expression shall be implicitly converted to the type needed for the
       context in which it is used. A string value shall be converted to a
       numeric value either by the equivalent of the following calls to
       functions defined by the ISO C standard:


           setlocale(LC_NUMERIC, "");
           _n_u_m_e_r_i_c___v_a_l_u_e = atof(_s_t_r_i_n_g___v_a_l_u_e);

       or by converting the initial portion of the string to type ddoouubbllee
       representation as follows:

              The input string is decomposed into two parts: an initial,
              possibly empty, sequence of white-space characters (as specified
              by _i_s_s_p_a_c_e()) and a subject sequence interpreted as a floating-
              point constant.

              The expected form of the subject sequence is an optional ''++'' or
              ''--'' sign, then a non-empty sequence of digits optionally
              containing a <period>, then an optional exponent part. An
              exponent part consists of ''ee'' or ''EE'', followed by an optional
              sign, followed by one or more decimal digits.

              The sequence starting with the first digit or the <period>
              (whichever occurs first) is interpreted as a floating constant
              of the C language, and if neither an exponent part nor a
              <period> appears, a <period> is assumed to follow the last digit
              in the string. If the subject sequence begins with a <hyphen-
              minus>, the value resulting from the conversion is negated.

       A numeric value that is exactly equal to the value of an integer (see
       _S_e_c_t_i_o_n _1_._1_._2, _C_o_n_c_e_p_t_s _D_e_r_i_v_e_d _f_r_o_m _t_h_e _I_S_O _C _S_t_a_n_d_a_r_d) shall be
       converted to a string by the equivalent of a call to the sspprriinnttff
       function (see _S_t_r_i_n_g _F_u_n_c_t_i_o_n_s) with the string ""%%dd"" as the _f_m_t
       argument and the numeric value being converted as the first and only
       _e_x_p_r argument. Any other numeric value shall be converted to a string
       by the equivalent of a call to the sspprriinnttff function with the value of
       the variable CCOONNVVFFMMTT as the _f_m_t argument and the numeric value being
       converted as the first and only _e_x_p_r argument. The result of the
       conversion is unspecified if the value of CCOONNVVFFMMTT is not a floating-
       point format specification. This volume of POSIX.1-2017 specifies no
       explicit conversions between numbers and strings. An application can
       force an expression to be treated as a number by adding zero to it, or
       can force it to be treated as a string by concatenating the null string
       ("""") to it.

       A string value shall be considered a _n_u_m_e_r_i_c _s_t_r_i_n_g if it comes from
       one of the following:

        1. Field variables

        2. Input from the _g_e_t_l_i_n_e() function

        3. FFIILLEENNAAMMEE

        4. AARRGGVV array elements

        5. EENNVVIIRROONN array elements

        6. Array elements created by the _s_p_l_i_t() function

        7. A command line variable assignment

        8. Variable assignment from another numeric string variable

       and an implementation-dependent condition corresponding to either case
       (a) or (b) below is met.

        a. After the equivalent of the following calls to functions defined by
           the ISO C standard, _s_t_r_i_n_g___v_a_l_u_e___e_n_d would differ from
           _s_t_r_i_n_g___v_a_l_u_e, and any characters before the terminating null
           character in _s_t_r_i_n_g___v_a_l_u_e___e_n_d would be <blank> characters:


               char *string_value_end;
               setlocale(LC_NUMERIC, "");
               numeric_value = strtod (string_value, &string_value_end);

        b. After all the following conversions have been applied, the
           resulting string would lexically be recognized as a NNUUMMBBEERR token as
           described by the lexical conventions in _G_r_a_m_m_a_r:

           --  All leading and trailing <blank> characters are discarded.

           --  If the first non-<blank> is ''++'' or ''--'', it is discarded.

           --  Each occurrence of the decimal point character from the current
               locale is changed to a <period>.
       In case (a) the numeric value of the _n_u_m_e_r_i_c _s_t_r_i_n_g shall be the value
       that would be returned by the _s_t_r_t_o_d() call. In case (b) if the first
       non-<blank> is ''--'', the numeric value of the _n_u_m_e_r_i_c _s_t_r_i_n_g shall be
       the negation of the numeric value of the recognized NNUUMMBBEERR token;
       otherwise, the numeric value of the _n_u_m_e_r_i_c _s_t_r_i_n_g shall be the numeric
       value of the recognized NNUUMMBBEERR token. Whether or not a string is a
       _n_u_m_e_r_i_c _s_t_r_i_n_g shall be relevant only in contexts where that term is
       used in this section.

       When an expression is used in a Boolean context, if it has a numeric
       value, a value of zero shall be treated as false and any other value
       shall be treated as true. Otherwise, a string value of the null string
       shall be treated as false and any other value shall be treated as true.
       A Boolean context shall be one of the following:

        *  The first subexpression of a conditional expression

        *  An expression operated on by logical NOT, logical AND, or logical
           OR

        *  The second expression of a ffoorr statement

        *  The expression of an iiff statement

        *  The expression of the wwhhiillee clause in either a wwhhiillee or ddoo...wwhhiillee
           statement

        *  An expression used as a pattern (as in Overall Program Structure)

       All arithmetic shall follow the semantics of floating-point arithmetic
       as specified by the ISO C standard (see _S_e_c_t_i_o_n _1_._1_._2, _C_o_n_c_e_p_t_s _D_e_r_i_v_e_d
       _f_r_o_m _t_h_e _I_S_O _C _S_t_a_n_d_a_r_d).

       The value of the expression:


           _e_x_p_r_1 ^ _e_x_p_r_2

       shall be equivalent to the value returned by the ISO C standard
       function call:


           pow(_e_x_p_r_1, _e_x_p_r_2)

       The expression:


           lvalue ^= _e_x_p_r

       shall be equivalent to the ISO C standard expression:


           lvalue = pow(lvalue, _e_x_p_r)

       except that lvalue shall be evaluated only once. The value of the
       expression:


           _e_x_p_r_1 % _e_x_p_r_2

       shall be equivalent to the value returned by the ISO C standard
       function call:


           fmod(_e_x_p_r_1, _e_x_p_r_2)

       The expression:


           lvalue %= _e_x_p_r

       shall be equivalent to the ISO C standard expression:


           lvalue = fmod(lvalue, _e_x_p_r)

       except that lvalue shall be evaluated only once.

       Variables and fields shall be set by the assignment statement:


           lvalue = _e_x_p_r_e_s_s_i_o_n

       and the type of _e_x_p_r_e_s_s_i_o_n shall determine the resulting variable type.
       The assignment includes the arithmetic assignments (""++=="", ""--=="", ""**=="",
       ""//=="", ""%%=="", ""^^=="", ""++++"", ""----"") all of which shall produce a numeric
       result. The left-hand side of an assignment and the target of increment
       and decrement operators can be one of a variable, an array with index,
       or a field selector.

       The _a_w_k language supplies arrays that are used for storing numbers or
       strings.  Arrays need not be declared. They shall initially be empty,
       and their sizes shall change dynamically. The subscripts, or element
       identifiers, are strings, providing a type of associative array
       capability. An array name followed by a subscript within square
       brackets can be used as an lvalue and thus as an expression, as
       described in the grammar; see _G_r_a_m_m_a_r.  Unsubscripted array names can
       be used in only the following contexts:

        *  A parameter in a function definition or function call

        *  The NNAAMMEE token following any use of the keyword iinn as specified in
           the grammar (see _G_r_a_m_m_a_r); if the name used in this context is not
           an array name, the behavior is undefined

       A valid array _i_n_d_e_x shall consist of one or more <comma>-separated
       expressions, similar to the way in which multi-dimensional arrays are
       indexed in some programming languages. Because _a_w_k arrays are really
       one-dimensional, such a <comma>-separated list shall be converted to a
       single string by concatenating the string values of the separate
       expressions, each separated from the other by the value of the SSUUBBSSEEPP
       variable. Thus, the following two index operations shall be equivalent:


           _v_a_r[[_e_x_p_r_1, _e_x_p_r_2, ... _e_x_p_r_n]]

           _v_a_r[[_e_x_p_r_1 SUBSEP _e_x_p_r_2 SUBSEP ... SUBSEP _e_x_p_r_n]]

       The application shall ensure that a multi-dimensioned _i_n_d_e_x used with
       the iinn operator is parenthesized. The iinn operator, which tests for the
       existence of a particular array element, shall not cause that element
       to exist. Any other reference to a nonexistent array element shall
       automatically create it.

       Comparisons (with the ''<<'', ""<<=="", ""!!=="", ""===="", ''>>'', and "">>=="" operators)
       shall be made numerically if both operands are numeric, if one is
       numeric and the other has a string value that is a numeric string, or
       if one is numeric and the other has the uninitialized value.
       Otherwise, operands shall be converted to strings as required and a
       string comparison shall be made as follows:

        *  For the ""!!=="" and ""===="" operators, the strings should be compared to
           check if they are identical but may be compared using the locale-
           specific collation sequence to check if they collate equally.

        *  For the other operators, the strings shall be compared using the
           locale-specific collation sequence.

       The value of the comparison expression shall be 1 if the relation is
       true, or 0 if the relation is false.

   VVaarriiaabblleess aanndd SSppeecciiaall VVaarriiaabblleess
       Variables can be used in an _a_w_k program by referencing them. With the
       exception of function parameters (see _U_s_e_r_-_D_e_f_i_n_e_d _F_u_n_c_t_i_o_n_s), they are
       not explicitly declared. Function parameter names shall be local to the
       function; all other variable names shall be global. The same name shall
       not be used as both a function parameter name and as the name of a
       function or a special _a_w_k variable. The same name shall not be used
       both as a variable name with global scope and as the name of a
       function. The same name shall not be used within the same scope both as
       a scalar variable and as an array.  Uninitialized variables, including
       scalar variables, array elements, and field variables, shall have an
       uninitialized value. An uninitialized value shall have both a numeric
       value of zero and a string value of the empty string. Evaluation of
       variables with an uninitialized value, to either string or numeric,
       shall be determined by the context in which they are used.

       Field variables shall be designated by a ''$$'' followed by a number or
       numerical expression. The effect of the field number _e_x_p_r_e_s_s_i_o_n
       evaluating to anything other than a non-negative integer is
       unspecified; uninitialized variables or string values need not be
       converted to numeric values in this context. New field variables can be
       created by assigning a value to them. References to nonexistent fields
       (that is, fields after $NNFF), shall evaluate to the uninitialized value.
       Such references shall not create new fields. However, assigning to a
       nonexistent field (for example, $(NNFF+2)=5) shall increase the value of
       NNFF; create any intervening fields with the uninitialized value; and
       cause the value of $0 to be recomputed, with the fields being separated
       by the value of OOFFSS.  Each field variable shall have a string value or
       an uninitialized value when created. Field variables shall have the
       uninitialized value when created from $0 using FFSS and the variable does
       not contain any characters. If appropriate, the field variable shall be
       considered a numeric string (see _E_x_p_r_e_s_s_i_o_n_s _i_n _a_w_k).

       Implementations shall support the following other special variables
       that are set by _a_w_k:

       AARRGGCC      The number of elements in the AARRGGVV array.

       AARRGGVV      An array of command line arguments, excluding options and the
                 _p_r_o_g_r_a_m argument, numbered from zero to AARRGGCC-1.

                 The arguments in AARRGGVV can be modified or added to; AARRGGCC can
                 be altered. As each input file ends, _a_w_k shall treat the next
                 non-null element of AARRGGVV, up to the current value of AARRGGCC-1,
                 inclusive, as the name of the next input file. Thus, setting
                 an element of AARRGGVV to null means that it shall not be treated
                 as an input file. The name ''--'' indicates the standard input.
                 If an argument matches the format of an _a_s_s_i_g_n_m_e_n_t operand,
                 this argument shall be treated as an _a_s_s_i_g_n_m_e_n_t rather than a
                 _f_i_l_e argument.

       CCOONNVVFFMMTT   The pprriinnttff format for converting numbers to strings (except
                 for output statements, where OOFFMMTT is used); ""%%..66gg"" by
                 default.

       EENNVVIIRROONN   An array representing the value of the environment, as
                 described in the _e_x_e_c functions defined in the System
                 Interfaces volume of POSIX.1-2017. The indices of the array
                 shall be strings consisting of the names of the environment
                 variables, and the value of each array element shall be a
                 string consisting of the value of that variable. If
                 appropriate, the environment variable shall be considered a
                 _n_u_m_e_r_i_c _s_t_r_i_n_g (see _E_x_p_r_e_s_s_i_o_n_s _i_n _a_w_k); the array element
                 shall also have its numeric value.

                 In all cases where the behavior of _a_w_k is affected by
                 environment variables (including the environment of any
                 commands that _a_w_k executes via the ssyysstteemm function or via
                 pipeline redirections with the pprriinntt statement, the pprriinnttff
                 statement, or the ggeettlliinnee function), the environment used
                 shall be the environment at the time _a_w_k began executing; it
                 is implementation-defined whether any modification of EENNVVIIRROONN
                 affects this environment.

       FFIILLEENNAAMMEE  A pathname of the current input file. Inside a BBEEGGIINN action
                 the value is undefined. Inside an EENNDD action the value shall
                 be the name of the last input file processed.

       FFNNRR       The ordinal number of the current record in the current file.
                 Inside a BBEEGGIINN action the value shall be zero. Inside an EENNDD
                 action the value shall be the number of the last record
                 processed in the last file processed.

       FFSS        Input field separator regular expression; a <space> by
                 default.

       NNFF        The number of fields in the current record. Inside a BBEEGGIINN
                 action, the use of NNFF is undefined unless a ggeettlliinnee function
                 without a _v_a_r argument is executed previously. Inside an EENNDD
                 action, NNFF shall retain the value it had for the last record
                 read, unless a subsequent, redirected, ggeettlliinnee function
                 without a _v_a_r argument is performed prior to entering the EENNDD
                 action.

       NNRR        The ordinal number of the current record from the start of
                 input.  Inside a BBEEGGIINN action the value shall be zero. Inside
                 an EENNDD action the value shall be the number of the last
                 record processed.

       OOFFMMTT      The pprriinnttff format for converting numbers to strings in output
                 statements (see _O_u_t_p_u_t _S_t_a_t_e_m_e_n_t_s); ""%%..66gg"" by default. The
                 result of the conversion is unspecified if the value of OOFFMMTT
                 is not a floating-point format specification.

       OOFFSS       The pprriinntt statement output field separator; <space> by
                 default.

       OORRSS       The pprriinntt statement output record separator; a <newline> by
                 default.

       RRLLEENNGGTTHH   The length of the string matched by the mmaattcchh function.

       RRSS        The first character of the string value of RRSS shall be the
                 input record separator; a <newline> by default. If RRSS
                 contains more than one character, the results are
                 unspecified. If RRSS is null, then records are separated by
                 sequences consisting of a <newline> plus one or more blank
                 lines, leading or trailing blank lines shall not result in
                 empty records at the beginning or end of the input, and a
                 <newline> shall always be a field separator, no matter what
                 the value of FFSS is.

       RRSSTTAARRTT    The starting position of the string matched by the mmaattcchh
                 function, numbering from 1. This shall always be equivalent
                 to the return value of the mmaattcchh function.

       SSUUBBSSEEPP    The subscript separator string for multi-dimensional arrays;
                 the default value is implementation-defined.

   RReegguullaarr EExxpprreessssiioonnss
       The _a_w_k utility shall make use of the extended regular expression
       notation (see the Base Definitions volume of POSIX.1-2017, _S_e_c_t_i_o_n _9_._4,
       _E_x_t_e_n_d_e_d _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s) except that it shall allow the use of C-
       language conventions for escaping special characters within the EREs,
       as specified in the table in the Base Definitions volume of
       POSIX.1-2017, _C_h_a_p_t_e_r _5, _F_i_l_e _F_o_r_m_a_t _N_o_t_a_t_i_o_n (''\\\\'', ''\\aa'', ''\\bb'', ''\\ff'',
       ''\\nn'', ''\\rr'', ''\\tt'', ''\\vv'') and the following table; these escape sequences
       shall be recognized both inside and outside bracket expressions. Note
       that records need not be separated by <newline> characters and string
       constants can contain <newline> characters, so even the ""\\nn"" sequence
       is valid in _a_w_k EREs. Using a <slash> character within an ERE requires
       the escaping shown in the following table.

                         TTaabbllee 44--22:: EEssccaappee SSeeqquueenncceess iinn _a_w_k

 +---------+------------------------------------+------------------------------------+
 | EEssccaappee  |                                    |                                    |
 |SSeeqquueennccee |            DDeessccrriippttiioonn             |              MMeeaanniinngg               |
 +---------+------------------------------------+------------------------------------+
 |\"       | <backslash> <quotation-mark>       | <quotation-mark> character         |
 +---------+------------------------------------+------------------------------------+
 |\/       | <backslash> <slash>                | <slash> character                  |
 +---------+------------------------------------+------------------------------------+
 |\ddd     | A <backslash> character followed   | The character whose encoding is    |
 |         | by the longest sequence of one,    | represented by the one, two, or    |
 |         | two, or three octal-digit          | three-digit octal integer. Multi-  |
 |         | characters (01234567). If all of   | byte characters require multiple,  |
 |         | the digits are 0 (that is,         | concatenated escape sequences of   |
 |         | representation of the NUL          | this type, including the leading   |
 |         | character), the behavior is        | <backslash> for each byte.         |
 |         | undefined.                         |                                    |
 +---------+------------------------------------+------------------------------------+
 |\c       | A <backslash> character followed   | Undefined                          |
 |         | by any character not described in  |                                    |
 |         | this table or in the table in the  |                                    |
 |         | Base Definitions volume of         |                                    |
 |         | POSIX.1-2017, _C_h_a_p_t_e_r _5, _F_i_l_e      |                                    |
 |         | _F_o_r_m_a_t _N_o_t_a_t_i_o_n (''\\\\'', ''\\aa'', ''\\bb'', |                                    |
 |         | ''\\ff'', ''\\nn'', ''\\rr'', ''\\tt'', ''\\vv'').     |                                    |
 +---------+------------------------------------+------------------------------------+
       A regular expression can be matched against a specific field or string
       by using one of the two regular expression matching operators, ''~~'' and
       ""!!~~"".  These operators shall interpret their right-hand operand as a
       regular expression and their left-hand operand as a string. If the
       regular expression matches the string, the ''~~'' expression shall
       evaluate to a value of 1, and the ""!!~~"" expression shall evaluate to a
       value of 0. (The regular expression matching operation is as defined by
       the term matched in the Base Definitions volume of POSIX.1-2017,
       _S_e_c_t_i_o_n _9_._1, _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n _D_e_f_i_n_i_t_i_o_n_s, where a match occurs on
       any part of the string unless the regular expression is limited with
       the <circumflex> or <dollar-sign> special characters.) If the regular
       expression does not match the string, the ''~~'' expression shall evaluate
       to a value of 0, and the ""!!~~"" expression shall evaluate to a value of
       1. If the right-hand operand is any expression other than the lexical
       token EERREE, the string value of the expression shall be interpreted as
       an extended regular expression, including the escape conventions
       described above.  Note that these same escape conventions shall also be
       applied in determining the value of a string literal (the lexical token
       SSTTRRIINNGG), and thus shall be applied a second time when a string literal
       is used in this context.

       When an EERREE token appears as an expression in any context other than as
       the right-hand of the ''~~'' or ""!!~~"" operator or as one of the built-in
       function arguments described below, the value of the resulting
       expression shall be the equivalent of:


           $0 ~ /_e_r_e/

       The _e_r_e argument to the ggssuubb, mmaattcchh, ssuubb functions, and the _f_s argument
       to the sspplliitt function (see _S_t_r_i_n_g _F_u_n_c_t_i_o_n_s) shall be interpreted as
       extended regular expressions. These can be either EERREE tokens or
       arbitrary expressions, and shall be interpreted in the same manner as
       the right-hand side of the ''~~'' or ""!!~~"" operator.

       An extended regular expression can be used to separate fields by
       assigning a string containing the expression to the built-in variable
       FFSS, either directly or as a consequence of using the --FF _s_e_p_s_t_r_i_n_g
       option.  The default value of the FFSS variable shall be a single
       <space>.  The following describes FFSS behavior:

        1. If FFSS is a null string, the behavior is unspecified.

        2. If FFSS is a single character:

            a. If FFSS is <space>, skip leading and trailing <blank> and
               <newline> characters; fields shall be delimited by sets of one
               or more <blank> or <newline> characters.

            b. Otherwise, if FFSS is any other character _c, fields shall be
               delimited by each single occurrence of _c.

        3. Otherwise, the string value of FFSS shall be considered to be an
           extended regular expression. Each occurrence of a sequence matching
           the extended regular expression shall delimit fields.

       Except for the ''~~'' and ""!!~~"" operators, and in the ggssuubb, mmaattcchh, sspplliitt,
       and ssuubb built-in functions, ERE matching shall be based on input
       records; that is, record separator characters (the first character of
       the value of the variable RRSS, <newline> by default) cannot be embedded
       in the expression, and no expression shall match the record separator
       character. If the record separator is not <newline>, <newline>
       characters embedded in the expression can be matched. For the ''~~'' and
       ""!!~~"" operators, and in those four built-in functions, ERE matching
       shall be based on text strings; that is, any character (including
       <newline> and the record separator) can be embedded in the pattern, and
       an appropriate pattern shall match any character. However, in all _a_w_k
       ERE matching, the use of one or more NUL characters in the pattern,
       input record, or text string produces undefined results.

   PPaatttteerrnnss
       A _p_a_t_t_e_r_n is any valid _e_x_p_r_e_s_s_i_o_n, a range specified by two expressions
       separated by a comma, or one of the two special patterns BBEEGGIINN or EENNDD.

   SSppeecciiaall PPaatttteerrnnss
       The _a_w_k utility shall recognize two special patterns, BBEEGGIINN and EENNDD.
       Each BBEEGGIINN pattern shall be matched once and its associated action
       executed before the first record of input is read--except possibly by
       use of the ggeettlliinnee function (see _I_n_p_u_t_/_O_u_t_p_u_t _a_n_d _G_e_n_e_r_a_l _F_u_n_c_t_i_o_n_s) in
       a prior BBEEGGIINN action--and before command line assignment is done. Each
       EENNDD pattern shall be matched once and its associated action executed
       after the last record of input has been read. These two patterns shall
       have associated actions.

       BBEEGGIINN and EENNDD shall not combine with other patterns. Multiple BBEEGGIINN and
       EENNDD patterns shall be allowed. The actions associated with the BBEEGGIINN
       patterns shall be executed in the order specified in the program, as
       are the EENNDD actions. An EENNDD pattern can precede a BBEEGGIINN pattern in a
       program.

       If an _a_w_k program consists of only actions with the pattern BBEEGGIINN, and
       the BBEEGGIINN action contains no ggeettlliinnee function, _a_w_k shall exit without
       reading its input when the last statement in the last BBEEGGIINN action is
       executed. If an _a_w_k program consists of only actions with the pattern
       EENNDD or only actions with the patterns BBEEGGIINN and EENNDD, the input shall be
       read before the statements in the EENNDD actions are executed.

   EExxpprreessssiioonn PPaatttteerrnnss
       An expression pattern shall be evaluated as if it were an expression in
       a Boolean context. If the result is true, the pattern shall be
       considered to match, and the associated action (if any) shall be
       executed. If the result is false, the action shall not be executed.

   PPaatttteerrnn RRaannggeess
       A pattern range consists of two expressions separated by a comma; in
       this case, the action shall be performed for all records between a
       match of the first expression and the following match of the second
       expression, inclusive. At this point, the pattern range can be repeated
       starting at input records subsequent to the end of the matched range.

   AAccttiioonnss
       An action is a sequence of statements as shown in the grammar in
       _G_r_a_m_m_a_r.  Any single statement can be replaced by a statement list
       enclosed in curly braces. The application shall ensure that statements
       in a statement list are separated by <newline> or <semicolon>
       characters. Statements in a statement list shall be executed
       sequentially in the order that they appear.

       The _e_x_p_r_e_s_s_i_o_n acting as the conditional in an iiff statement shall be
       evaluated and if it is non-zero or non-null, the following statement
       shall be executed; otherwise, if eellssee is present, the statement
       following the eellssee shall be executed.

       The iiff, wwhhiillee, ddoo...wwhhiillee, ffoorr, bbrreeaakk, and ccoonnttiinnuuee statements are
       based on the ISO C standard (see _S_e_c_t_i_o_n _1_._1_._2, _C_o_n_c_e_p_t_s _D_e_r_i_v_e_d _f_r_o_m
       _t_h_e _I_S_O _C _S_t_a_n_d_a_r_d), except that the Boolean expressions shall be
       treated as described in _E_x_p_r_e_s_s_i_o_n_s _i_n _a_w_k, and except in the case of:


           for (_v_a_r_i_a_b_l_e in _a_r_r_a_y)

       which shall iterate, assigning each _i_n_d_e_x of _a_r_r_a_y to _v_a_r_i_a_b_l_e in an
       unspecified order. The results of adding new elements to _a_r_r_a_y within
       such a ffoorr loop are undefined. If a bbrreeaakk or ccoonnttiinnuuee statement occurs
       outside of a loop, the behavior is undefined.

       The ddeelleettee statement shall remove an individual array element. Thus,
       the following code deletes an entire array:


           for (index in array)
               delete array[index]

       The nneexxtt statement shall cause all further processing of the current
       input record to be abandoned. The behavior is undefined if a nneexxtt
       statement appears or is invoked in a BBEEGGIINN or EENNDD action.

       The eexxiitt statement shall invoke all EENNDD actions in the order in which
       they occur in the program source and then terminate the program without
       reading further input. An eexxiitt statement inside an EENNDD action shall
       terminate the program without further execution of EENNDD actions. If an
       expression is specified in an eexxiitt statement, its numeric value shall
       be the exit status of _a_w_k, unless subsequent errors are encountered or
       a subsequent eexxiitt statement with an expression is executed.

   OOuuttppuutt SSttaatteemmeennttss
       Both pprriinntt and pprriinnttff statements shall write to standard output by
       default. The output shall be written to the location specified by
       _o_u_t_p_u_t___r_e_d_i_r_e_c_t_i_o_n if one is supplied, as follows:


           > _e_x_p_r_e_s_s_i_o_n
           >> _e_x_p_r_e_s_s_i_o_n
           | _e_x_p_r_e_s_s_i_o_n

       In all cases, the _e_x_p_r_e_s_s_i_o_n shall be evaluated to produce a string
       that is used as a pathname into which to write (for ''>>'' or "">>>>"") or as
       a command to be executed (for ''||'').  Using the first two forms, if the
       file of that name is not currently open, it shall be opened, creating
       it if necessary and using the first form, truncating the file. The
       output then shall be appended to the file. As long as the file remains
       open, subsequent calls in which _e_x_p_r_e_s_s_i_o_n evaluates to the same string
       value shall simply append output to the file. The file remains open
       until the cclloossee function (see _I_n_p_u_t_/_O_u_t_p_u_t _a_n_d _G_e_n_e_r_a_l _F_u_n_c_t_i_o_n_s) is
       called with an expression that evaluates to the same string value.

       The third form shall write output onto a stream piped to the input of a
       command. The stream shall be created if no stream is currently open
       with the value of _e_x_p_r_e_s_s_i_o_n as its command name. The stream created
       shall be equivalent to one created by a call to the _p_o_p_e_n() function
       defined in the System Interfaces volume of POSIX.1-2017 with the value
       of _e_x_p_r_e_s_s_i_o_n as the _c_o_m_m_a_n_d argument and a value of _w as the _m_o_d_e
       argument. As long as the stream remains open, subsequent calls in which
       _e_x_p_r_e_s_s_i_o_n evaluates to the same string value shall write output to the
       existing stream. The stream shall remain open until the cclloossee function
       (see _I_n_p_u_t_/_O_u_t_p_u_t _a_n_d _G_e_n_e_r_a_l _F_u_n_c_t_i_o_n_s) is called with an expression
       that evaluates to the same string value.  At that time, the stream
       shall be closed as if by a call to the _p_c_l_o_s_e() function defined in the
       System Interfaces volume of POSIX.1-2017.

       As described in detail by the grammar in _G_r_a_m_m_a_r, these output
       statements shall take a <comma>-separated list of _e_x_p_r_e_s_s_i_o_ns referred
       to in the grammar by the non-terminal symbols eexxpprr__lliisstt,
       pprriinntt__eexxpprr__lliisstt, or pprriinntt__eexxpprr__lliisstt__oopptt.  This list is referred to here
       as the _e_x_p_r_e_s_s_i_o_n _l_i_s_t, and each member is referred to as an _e_x_p_r_e_s_s_i_o_n
       _a_r_g_u_m_e_n_t.

       The pprriinntt statement shall write the value of each expression argument
       onto the indicated output stream separated by the current output field
       separator (see variable OOFFSS above), and terminated by the output record
       separator (see variable OORRSS above). All expression arguments shall be
       taken as strings, being converted if necessary; this conversion shall
       be as described in _E_x_p_r_e_s_s_i_o_n_s _i_n _a_w_k, with the exception that the
       pprriinnttff format in OOFFMMTT shall be used instead of the value in CCOONNVVFFMMTT.
       An empty expression list shall stand for the whole input record ($0).

       The pprriinnttff statement shall produce output based on a notation similar
       to the File Format Notation used to describe file formats in this
       volume of POSIX.1-2017 (see the Base Definitions volume of
       POSIX.1-2017, _C_h_a_p_t_e_r _5, _F_i_l_e _F_o_r_m_a_t _N_o_t_a_t_i_o_n).  Output shall be
       produced as specified with the first _e_x_p_r_e_s_s_i_o_n argument as the string
       _f_o_r_m_a_t and subsequent _e_x_p_r_e_s_s_i_o_n arguments as the strings _a_r_g_1 to _a_r_g_n,
       inclusive, with the following exceptions:

        1. The _f_o_r_m_a_t shall be an actual character string rather than a
           graphical representation. Therefore, it cannot contain empty
           character positions. The <space> in the _f_o_r_m_a_t string, in any
           context other than a _f_l_a_g of a conversion specification, shall be
           treated as an ordinary character that is copied to the output.

        2. If the character set contains a ''' character and that character
           appears in the _f_o_r_m_a_t string, it shall be treated as an ordinary
           character that is copied to the output.

        3. The _e_s_c_a_p_e _s_e_q_u_e_n_c_e_s beginning with a <backslash> character shall
           be treated as sequences of ordinary characters that are copied to
           the output. Note that these same sequences shall be interpreted
           lexically by _a_w_k when they appear in literal strings, but they
           shall not be treated specially by the pprriinnttff statement.

        4. A _f_i_e_l_d _w_i_d_t_h or _p_r_e_c_i_s_i_o_n can be specified as the ''**'' character
           instead of a digit string. In this case the next argument from the
           expression list shall be fetched and its numeric value taken as the
           field width or precision.

        5. The implementation shall not precede or follow output from the dd or
           uu conversion specifier characters with <blank> characters not
           specified by the _f_o_r_m_a_t string.

        6. The implementation shall not precede output from the oo conversion
           specifier character with leading zeros not specified by the _f_o_r_m_a_t
           string.

        7. For the cc conversion specifier character: if the argument has a
           numeric value, the character whose encoding is that value shall be
           output. If the value is zero or is not the encoding of any
           character in the character set, the behavior is undefined. If the
           argument does not have a numeric value, the first character of the
           string value shall be output; if the string does not contain any
           characters, the behavior is undefined.

        8. For each conversion specification that consumes an argument, the
           next expression argument shall be evaluated. With the exception of
           the cc conversion specifier character, the value shall be converted
           (according to the rules specified in _E_x_p_r_e_s_s_i_o_n_s _i_n _a_w_k) to the
           appropriate type for the conversion specification.

        9. If there are insufficient expression arguments to satisfy all the
           conversion specifications in the _f_o_r_m_a_t string, the behavior is
           undefined.

       10. If any character sequence in the _f_o_r_m_a_t string begins with a ''%%''
           character, but does not form a valid conversion specification, the
           behavior is unspecified.

       Both pprriinntt and pprriinnttff can output at least {LINE_MAX} bytes.

   FFuunnccttiioonnss
       The _a_w_k language has a variety of built-in functions: arithmetic,
       string, input/output, and general.

   AArriitthhmmeettiicc FFuunnccttiioonnss
       The arithmetic functions, except for iinntt, shall be based on the ISO C
       standard (see _S_e_c_t_i_o_n _1_._1_._2, _C_o_n_c_e_p_t_s _D_e_r_i_v_e_d _f_r_o_m _t_h_e _I_S_O _C _S_t_a_n_d_a_r_d).
       The behavior is undefined in cases where the ISO C standard specifies
       that an error be returned or that the behavior is undefined. Although
       the grammar (see _G_r_a_m_m_a_r) permits built-in functions to appear with no
       arguments or parentheses, unless the argument or parentheses are
       indicated as optional in the following list (by displaying them within
       the ""[[]]"" brackets), such use is undefined.

       aattaann22(_y,_x)
                 Return arctangent of _y/_x in radians in the range
                 [-<pi>,<pi>].

       ccooss(_x)    Return cosine of _x, where _x is in radians.

       ssiinn(_x)    Return sine of _x, where _x is in radians.

       eexxpp(_x)    Return the exponential function of _x.

       lloogg(_x)    Return the natural logarithm of _x.

       ssqqrrtt(_x)   Return the square root of _x.

       iinntt(_x)    Return the argument truncated to an integer. Truncation shall
                 be toward 0 when _x>0.

       rraanndd()    Return a random number _n, such that 0<=_n<1.

       ssrraanndd([[_e_x_p_r]])
                 Set the seed value for _r_a_n_d to _e_x_p_r or use the time of day if
                 _e_x_p_r is omitted. The previous seed value shall be returned.

   SSttrriinngg FFuunnccttiioonnss
       The string functions in the following list shall be supported.
       Although the grammar (see _G_r_a_m_m_a_r) permits built-in functions to appear
       with no arguments or parentheses, unless the argument or parentheses
       are indicated as optional in the following list (by displaying them
       within the ""[[]]"" brackets), such use is undefined.

       ggssuubb(_e_r_e, _r_e_p_l[[, _i_n]])
                 Behave like ssuubb (see below), except that it shall replace all
                 occurrences of the regular expression (like the _e_d utility
                 global substitute) in $0 or in the _i_n argument, when
                 specified.

       iinnddeexx(_s, _t)
                 Return the position, in characters, numbering from 1, in
                 string _s where string _t first occurs, or zero if it does not
                 occur at all.

       lleennggtthh[[([[_s]])]]
                 Return the length, in characters, of its argument taken as a
                 string, or of the whole record, $0, if there is no argument.

       mmaattcchh(_s, _e_r_e)
                 Return the position, in characters, numbering from 1, in
                 string _s where the extended regular expression _e_r_e occurs, or
                 zero if it does not occur at all. RSTART shall be set to the
                 starting position (which is the same as the returned value),
                 zero if no match is found; RLENGTH shall be set to the length
                 of the matched string, -1 if no match is found.

       sspplliitt(_s, _a[[, _f_s ]])
                 Split the string _s into array elements _a[1], _a[2], ..., _a[_n],
                 and return _n.  All elements of the array shall be deleted
                 before the split is performed. The separation shall be done
                 with the ERE _f_s or with the field separator FFSS if _f_s is not
                 given. Each array element shall have a string value when
                 created and, if appropriate, the array element shall be
                 considered a numeric string (see _E_x_p_r_e_s_s_i_o_n_s _i_n _a_w_k).  The
                 effect of a null string as the value of _f_s is unspecified.

       sspprriinnttff(_f_m_t, _e_x_p_r, _e_x_p_r, ...)
                 Format the expressions according to the pprriinnttff format given
                 by _f_m_t and return the resulting string.

       ssuubb((_e_r_e, _r_e_p_l[[, _i_n ]])
                 Substitute the string _r_e_p_l in place of the first instance of
                 the extended regular expression _E_R_E in string _i_n and return
                 the number of substitutions. An <ampersand> (''&&'') appearing
                 in the string _r_e_p_l shall be replaced by the string from _i_n
                 that matches the ERE. An <ampersand> preceded with a
                 <backslash> shall be interpreted as the literal <ampersand>
                 character. An occurrence of two consecutive <backslash>
                 characters shall be interpreted as just a single literal
                 <backslash> character. Any other occurrence of a <backslash>
                 (for example, preceding any other character) shall be treated
                 as a literal <backslash> character. Note that if _r_e_p_l is a
                 string literal (the lexical token SSTTRRIINNGG; see _G_r_a_m_m_a_r), the
                 handling of the <ampersand> character occurs after any
                 lexical processing, including any lexical <backslash>-escape
                 sequence processing. If _i_n is specified and it is not an
                 lvalue (see _E_x_p_r_e_s_s_i_o_n_s _i_n _a_w_k), the behavior is undefined.
                 If _i_n is omitted, _a_w_k shall use the current record ($0) in
                 its place.

       ssuubbssttrr(_s, _m[[, _n ]])
                 Return the at most _n-character substring of _s that begins at
                 position _m, numbering from 1. If _n is omitted, or if _n
                 specifies more characters than are left in the string, the
                 length of the substring shall be limited by the length of the
                 string _s.

       ttoolloowweerr(_s)
                 Return a string based on the string _s.  Each character in _s
                 that is an uppercase letter specified to have a ttoolloowweerr
                 mapping by the _L_C___C_T_Y_P_E category of the current locale shall
                 be replaced in the returned string by the lowercase letter
                 specified by the mapping. Other characters in _s shall be
                 unchanged in the returned string.

       ttoouuppppeerr(_s)
                 Return a string based on the string _s.  Each character in _s
                 that is a lowercase letter specified to have a ttoouuppppeerr
                 mapping by the _L_C___C_T_Y_P_E category of the current locale is
                 replaced in the returned string by the uppercase letter
                 specified by the mapping. Other characters in _s are unchanged
                 in the returned string.

       All of the preceding functions that take _E_R_E as a parameter expect a
       pattern or a string valued expression that is a regular expression as
       defined in _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s.

   IInnppuutt//OOuuttppuutt aanndd GGeenneerraall FFuunnccttiioonnss
       The input/output and general functions are:

       cclloossee(_e_x_p_r_e_s_s_i_o_n)
                 Close the file or pipe opened by a pprriinntt or pprriinnttff statement
                 or a call to ggeettlliinnee with the same string-valued _e_x_p_r_e_s_s_i_o_n.
                 The limit on the number of open _e_x_p_r_e_s_s_i_o_n arguments is
                 implementation-defined. If the close was successful, the
                 function shall return zero; otherwise, it shall return non-
                 zero.

       _e_x_p_r_e_s_s_i_o_n _| ggeettlliinnee [[_v_a_r]]
                 Read a record of input from a stream piped from the output of
                 a command. The stream shall be created if no stream is
                 currently open with the value of _e_x_p_r_e_s_s_i_o_n as its command
                 name. The stream created shall be equivalent to one created
                 by a call to the _p_o_p_e_n() function with the value of
                 _e_x_p_r_e_s_s_i_o_n as the _c_o_m_m_a_n_d argument and a value of _r as the
                 _m_o_d_e argument. As long as the stream remains open, subsequent
                 calls in which _e_x_p_r_e_s_s_i_o_n evaluates to the same string value
                 shall read subsequent records from the stream. The stream
                 shall remain open until the cclloossee function is called with an
                 expression that evaluates to the same string value. At that
                 time, the stream shall be closed as if by a call to the
                 _p_c_l_o_s_e() function. If _v_a_r is omitted, $0 and NNFF shall be set;
                 otherwise, _v_a_r shall be set and, if appropriate, it shall be
                 considered a numeric string (see _E_x_p_r_e_s_s_i_o_n_s _i_n _a_w_k).

                 The ggeettlliinnee operator can form ambiguous constructs when there
                 are unparenthesized operators (including concatenate) to the
                 left of the ''||'' (to the beginning of the expression
                 containing ggeettlliinnee).  In the context of the ''$$'' operator, ''||''
                 shall behave as if it had a lower precedence than ''$$''.  The
                 result of evaluating other operators is unspecified, and
                 conforming applications shall parenthesize properly all such
                 usages.

       ggeettlliinnee   Set $0 to the next input record from the current input file.
                 This form of ggeettlliinnee shall set the NNFF, NNRR, and FFNNRR variables.

       ggeettlliinnee _v_a_r
                 Set variable _v_a_r to the next input record from the current
                 input file and, if appropriate, _v_a_r shall be considered a
                 numeric string (see _E_x_p_r_e_s_s_i_o_n_s _i_n _a_w_k).  This form of
                 ggeettlliinnee shall set the FFNNRR and NNRR variables.

       ggeettlliinnee [[_v_a_r]] < _e_x_p_r_e_s_s_i_o_n
                 Read the next record of input from a named file. The
                 _e_x_p_r_e_s_s_i_o_n shall be evaluated to produce a string that is
                 used as a pathname.  If the file of that name is not
                 currently open, it shall be opened. As long as the stream
                 remains open, subsequent calls in which _e_x_p_r_e_s_s_i_o_n evaluates
                 to the same string value shall read subsequent records from
                 the file. The file shall remain open until the cclloossee function
                 is called with an expression that evaluates to the same
                 string value. If _v_a_r is omitted, $0 and NNFF shall be set;
                 otherwise, _v_a_r shall be set and, if appropriate, it shall be
                 considered a numeric string (see _E_x_p_r_e_s_s_i_o_n_s _i_n _a_w_k).

                 The ggeettlliinnee operator can form ambiguous constructs when there
                 are unparenthesized binary operators (including concatenate)
                 to the right of the ''<<'' (up to the end of the expression
                 containing the ggeettlliinnee).  The result of evaluating such a
                 construct is unspecified, and conforming applications shall
                 parenthesize properly all such usages.

       ssyysstteemm(_e_x_p_r_e_s_s_i_o_n)
                 Execute the command given by _e_x_p_r_e_s_s_i_o_n in a manner
                 equivalent to the _s_y_s_t_e_m() function defined in the System
                 Interfaces volume of POSIX.1-2017 and return the exit status
                 of the command.

       All forms of ggeettlliinnee shall return 1 for successful input, zero for end-
       of-file, and -1 for an error.

       Where strings are used as the name of a file or pipeline, the
       application shall ensure that the strings are textually identical. The
       terminology ``same string value'' implies that ``equivalent strings'',
       even those that differ only by <space> characters, represent different
       files.

   UUsseerr--DDeeffiinneedd FFuunnccttiioonnss
       The _a_w_k language also provides user-defined functions. Such functions
       can be defined as:


           function _n_a_m_e([[_p_a_r_a_m_e_t_e_r, ...]]) { _s_t_a_t_e_m_e_n_t_s }

       A function can be referred to anywhere in an _a_w_k program; in
       particular, its use can precede its definition. The scope of a function
       is global.

       Function parameters, if present, can be either scalars or arrays; the
       behavior is undefined if an array name is passed as a parameter that
       the function uses as a scalar, or if a scalar expression is passed as a
       parameter that the function uses as an array. Function parameters shall
       be passed by value if scalar and by reference if array name.

       The number of parameters in the function definition need not match the
       number of parameters in the function call. Excess formal parameters can
       be used as local variables. If fewer arguments are supplied in a
       function call than are in the function definition, the extra parameters
       that are used in the function body as scalars shall evaluate to the
       uninitialized value until they are otherwise initialized, and the extra
       parameters that are used in the function body as arrays shall be
       treated as uninitialized arrays where each element evaluates to the
       uninitialized value until otherwise initialized.

       When invoking a function, no white space can be placed between the
       function name and the opening parenthesis. Function calls can be nested
       and recursive calls can be made upon functions. Upon return from any
       nested or recursive function call, the values of all of the calling
       function's parameters shall be unchanged, except for array parameters
       passed by reference. The rreettuurrnn statement can be used to return a
       value. If a rreettuurrnn statement appears outside of a function definition,
       the behavior is undefined.

       In the function definition, <newline> characters shall be optional
       before the opening brace and after the closing brace. Function
       definitions can appear anywhere in the program where a _p_a_t_t_e_r_n_-_a_c_t_i_o_n
       pair is allowed.

   GGrraammmmaarr
       The grammar in this section and the lexical conventions in the
       following section shall together describe the syntax for _a_w_k programs.
       The general conventions for this style of grammar are described in
       _S_e_c_t_i_o_n _1_._3, _G_r_a_m_m_a_r _C_o_n_v_e_n_t_i_o_n_s.  A valid program can be represented
       as the non-terminal symbol _p_r_o_g_r_a_m in the grammar. This formal syntax
       shall take precedence over the preceding text syntax description.


           %token NAME NUMBER STRING ERE
           %token FUNC_NAME   /* Name followed by '(' without white space. */

           /* Keywords */
           %token       Begin   End
           /*          'BEGIN' 'END'                            */

           %token       Break   Continue   Delete   Do   Else
           /*          'break' 'continue' 'delete' 'do' 'else'  */

           %token       Exit   For   Function   If   In
           /*          'exit' 'for' 'function' 'if' 'in'        */

           %token       Next   Print   Printf   Return   While
           /*          'next' 'print' 'printf' 'return' 'while' */

           /* Reserved function names */
           %token BUILTIN_FUNC_NAME
                       /* One token for the following:
                        * atan2 cos sin exp log sqrt int rand srand
                        * gsub index length match split sprintf sub
                        * substr tolower toupper close system
                        */
           %token GETLINE
                       /* Syntactically different from other built-ins. */

           /* Two-character tokens. */
           %token ADD_ASSIGN SUB_ASSIGN MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN POW_ASSIGN
           /*     '+='       '-='       '*='       '/='       '%='       '^=' */

           %token OR   AND  NO_MATCH   EQ   LE   GE   NE   INCR  DECR  APPEND
           /*     '||' '&&' '!~' '==' '<=' '>=' '!=' '++'  '--'  '>>'   */

           /* One-character tokens. */
           %token '{' '}' '(' ')' '[' ']' ',' ';' NEWLINE
           %token '+' '-' '*' '%' '^' '!' '>' '<' '|' '?' ':' '~' '$' '='

           %start program
           %%

           program          : item_list
                            | item_list item
                            ;

           item_list        : /* empty */
                            | item_list item terminator
                            ;

           item             : action
                            | pattern action
                            | normal_pattern
                            | Function NAME      '(' param_list_opt ')'
                                  newline_opt action
                            | Function FUNC_NAME '(' param_list_opt ')'
                                  newline_opt action
                            ;

           param_list_opt   : /* empty */
                            | param_list
                            ;

           param_list       : NAME
                            | param_list ',' NAME
                            ;

           pattern          : normal_pattern
                            | special_pattern
                            ;

           normal_pattern   : expr
                            | expr ',' newline_opt expr
                            ;

           special_pattern  : Begin
                            | End
                            ;

           action           : '{' newline_opt                             '}'
                            | '{' newline_opt terminated_statement_list   '}'
                            | '{' newline_opt unterminated_statement_list '}'
                            ;

           terminator       : terminator NEWLINE
                            |            ';'
                            |            NEWLINE
                            ;

           terminated_statement_list : terminated_statement
                            | terminated_statement_list terminated_statement
                            ;

           unterminated_statement_list : unterminated_statement
                            | terminated_statement_list unterminated_statement
                            ;

           terminated_statement : action newline_opt
                            | If '(' expr ')' newline_opt terminated_statement
                            | If '(' expr ')' newline_opt terminated_statement
                                  Else newline_opt terminated_statement
                            | While '(' expr ')' newline_opt terminated_statement
                            | For '(' simple_statement_opt ';'
                                 expr_opt ';' simple_statement_opt ')' newline_opt
                                 terminated_statement
                            | For '(' NAME In NAME ')' newline_opt
                                 terminated_statement
                            | ';' newline_opt
                            | terminatable_statement NEWLINE newline_opt
                            | terminatable_statement ';'     newline_opt
                            ;

           unterminated_statement : terminatable_statement
                            | If '(' expr ')' newline_opt unterminated_statement
                            | If '(' expr ')' newline_opt terminated_statement
                                 Else newline_opt unterminated_statement
                            | While '(' expr ')' newline_opt unterminated_statement
                            | For '(' simple_statement_opt ';'
                             expr_opt ';' simple_statement_opt ')' newline_opt
                                 unterminated_statement
                            | For '(' NAME In NAME ')' newline_opt
                                 unterminated_statement
                            ;

           terminatable_statement : simple_statement
                            | Break
                            | Continue
                            | Next
                            | Exit expr_opt
                            | Return expr_opt
                            | Do newline_opt terminated_statement While '(' expr ')'
                            ;

           simple_statement_opt : /* empty */
                            | simple_statement
                            ;

           simple_statement : Delete NAME '[' expr_list ']'
                            | expr
                            | print_statement
                            ;

           print_statement  : simple_print_statement
                            | simple_print_statement output_redirection
                            ;

           simple_print_statement : Print  print_expr_list_opt
                            | Print  '(' multiple_expr_list ')'
                            | Printf print_expr_list
                            | Printf '(' multiple_expr_list ')'
                            ;

           output_redirection : '>'    expr
                            | APPEND expr
                            | '|'    expr
                            ;

           expr_list_opt    : /* empty */
                            | expr_list
                            ;

           expr_list        : expr
                            | multiple_expr_list
                            ;

           multiple_expr_list : expr ',' newline_opt expr
                            | multiple_expr_list ',' newline_opt expr
                            ;

           expr_opt         : /* empty */
                            | expr
                            ;

           expr             : unary_expr
                            | non_unary_expr
                            ;

           unary_expr       : '+' expr
                            | '-' expr
                            | unary_expr '^'      expr
                            | unary_expr '*'      expr
                            | unary_expr '/'      expr
                            | unary_expr '%'      expr
                            | unary_expr '+'      expr
                            | unary_expr '-'      expr
                            | unary_expr          non_unary_expr
                            | unary_expr '<'      expr
                            | unary_expr LE       expr
                            | unary_expr NE       expr
                            | unary_expr EQ       expr
                            | unary_expr '>'      expr
                            | unary_expr GE       expr
                            | unary_expr '~'      expr
                            | unary_expr NO_MATCH expr
                            | unary_expr In NAME
                            | unary_expr AND newline_opt expr
                            | unary_expr OR  newline_opt expr
                            | unary_expr '?' expr ':' expr
                            | unary_input_function
                            ;

           non_unary_expr   : '(' expr ')'
                            | '!' expr
                            | non_unary_expr '^'      expr
                            | non_unary_expr '*'      expr
                            | non_unary_expr '/'      expr
                            | non_unary_expr '%'      expr
                            | non_unary_expr '+'      expr
                            | non_unary_expr '-'      expr
                            | non_unary_expr          non_unary_expr
                            | non_unary_expr '<'      expr
                            | non_unary_expr LE       expr
                            | non_unary_expr NE       expr
                            | non_unary_expr EQ       expr
                            | non_unary_expr '>'      expr
                            | non_unary_expr GE       expr
                            | non_unary_expr '~'      expr
                            | non_unary_expr NO_MATCH expr
                            | non_unary_expr In NAME
                            | '(' multiple_expr_list ')' In NAME
                            | non_unary_expr AND newline_opt expr
                            | non_unary_expr OR  newline_opt expr
                            | non_unary_expr '?' expr ':' expr
                            | NUMBER
                            | STRING
                            | lvalue
                            | ERE
                            | lvalue INCR
                            | lvalue DECR
                            | INCR lvalue
                            | DECR lvalue
                            | lvalue POW_ASSIGN expr
                            | lvalue MOD_ASSIGN expr
                            | lvalue MUL_ASSIGN expr
                            | lvalue DIV_ASSIGN expr
                            | lvalue ADD_ASSIGN expr
                            | lvalue SUB_ASSIGN expr
                            | lvalue '=' expr
                            | FUNC_NAME '(' expr_list_opt ')'
                                 /* no white space allowed before '(' */
                            | BUILTIN_FUNC_NAME '(' expr_list_opt ')'
                            | BUILTIN_FUNC_NAME
                            | non_unary_input_function
                            ;

           print_expr_list_opt : /* empty */
                            | print_expr_list
                            ;

           print_expr_list  : print_expr
                            | print_expr_list ',' newline_opt print_expr
                            ;

           print_expr       : unary_print_expr
                            | non_unary_print_expr
                            ;

           unary_print_expr : '+' print_expr
                            | '-' print_expr
                            | unary_print_expr '^'      print_expr
                            | unary_print_expr '*'      print_expr
                            | unary_print_expr '/'      print_expr
                            | unary_print_expr '%'      print_expr
                            | unary_print_expr '+'      print_expr
                            | unary_print_expr '-'      print_expr
                            | unary_print_expr          non_unary_print_expr
                            | unary_print_expr '~'      print_expr
                            | unary_print_expr NO_MATCH print_expr
                            | unary_print_expr In NAME
                            | unary_print_expr AND newline_opt print_expr
                            | unary_print_expr OR  newline_opt print_expr
                            | unary_print_expr '?' print_expr ':' print_expr
                            ;

           non_unary_print_expr : '(' expr ')'
                            | '!' print_expr
                            | non_unary_print_expr '^'      print_expr
                            | non_unary_print_expr '*'      print_expr
                            | non_unary_print_expr '/'      print_expr
                            | non_unary_print_expr '%'      print_expr
                            | non_unary_print_expr '+'      print_expr
                            | non_unary_print_expr '-'      print_expr
                            | non_unary_print_expr          non_unary_print_expr
                            | non_unary_print_expr '~'      print_expr
                            | non_unary_print_expr NO_MATCH print_expr
                            | non_unary_print_expr In NAME
                            | '(' multiple_expr_list ')' In NAME
                            | non_unary_print_expr AND newline_opt print_expr
                            | non_unary_print_expr OR  newline_opt print_expr
                            | non_unary_print_expr '?' print_expr ':' print_expr
                            | NUMBER
                            | STRING
                            | lvalue
                            | ERE
                            | lvalue INCR
                            | lvalue DECR
                            | INCR lvalue
                            | DECR lvalue
                            | lvalue POW_ASSIGN print_expr
                            | lvalue MOD_ASSIGN print_expr
                            | lvalue MUL_ASSIGN print_expr
                            | lvalue DIV_ASSIGN print_expr
                            | lvalue ADD_ASSIGN print_expr
                            | lvalue SUB_ASSIGN print_expr
                            | lvalue '=' print_expr
                            | FUNC_NAME '(' expr_list_opt ')'
                                /* no white space allowed before '(' */
                            | BUILTIN_FUNC_NAME '(' expr_list_opt ')'
                            | BUILTIN_FUNC_NAME
                            ;

           lvalue           : NAME
                            | NAME '[' expr_list ']'
                            | '$' expr
                            ;

           non_unary_input_function : simple_get
                            | simple_get '<' expr
                            | non_unary_expr '|' simple_get
                            ;

           unary_input_function : unary_expr '|' simple_get
                            ;

           simple_get       : GETLINE
                            | GETLINE lvalue
                            ;

           newline_opt      : /* empty */
                            | newline_opt NEWLINE
                            ;

       This grammar has several ambiguities that shall be resolved as follows:

        *  Operator precedence and associativity shall be as described in
           _T_a_b_l_e _4_-_1_, _E_x_p_r_e_s_s_i_o_n_s _i_n _D_e_c_r_e_a_s_i_n_g _P_r_e_c_e_d_e_n_c_e _i_n _a_w_k.

        *  In case of ambiguity, an eellssee shall be associated with the most
           immediately preceding iiff that would satisfy the grammar.

        *  In some contexts, a <slash> (''//'') that is used to surround an ERE
           could also be the division operator.  This shall be resolved in
           such a way that wherever the division operator could appear, a
           <slash> is assumed to be the division operator. (There is no unary
           division operator.)

       Each expression in an _a_w_k program shall conform to the precedence and
       associativity rules, even when this is not needed to resolve an
       ambiguity. For example, because ''$$'' has higher precedence than ''++++'',
       the string ""$$xx++++----"" is not a valid _a_w_k expression, even though it is
       unambiguously parsed by the grammar as ""$$((xx++++))----"".

       One convention that might not be obvious from the formal grammar is
       where <newline> characters are acceptable. There are several obvious
       placements such as terminating a statement, and a <backslash> can be
       used to escape <newline> characters between any lexical tokens. In
       addition, <newline> characters without <backslash> characters can
       follow a comma, an open brace, logical AND operator (""&&&&""), logical OR
       operator (""||||""), the ddoo keyword, the eellssee keyword, and the closing
       parenthesis of an iiff, ffoorr, or wwhhiillee statement. For example:


           { print  $1,
                    $2 }

   LLeexxiiccaall CCoonnvveennttiioonnss
       The lexical conventions for _a_w_k programs, with respect to the preceding
       grammar, shall be as follows:

        1. Except as noted, _a_w_k shall recognize the longest possible token or
           delimiter beginning at a given point.

        2. A comment shall consist of any characters beginning with the
           <number-sign> character and terminated by, but excluding the next
           occurrence of, a <newline>.  Comments shall have no effect, except
           to delimit lexical tokens.

        3. The <newline> shall be recognized as the token NNEEWWLLIINNEE.

        4. A <backslash> character immediately followed by a <newline> shall
           have no effect.

        5. The token SSTTRRIINNGG shall represent a string constant. A string
           constant shall begin with the character ''""''.  Within a string
           constant, a <backslash> character shall be considered to begin an
           escape sequence as specified in the table in the Base Definitions
           volume of POSIX.1-2017, _C_h_a_p_t_e_r _5, _F_i_l_e _F_o_r_m_a_t _N_o_t_a_t_i_o_n (''\\\\'',
           ''\\aa'', ''\\bb'', ''\\ff'', ''\\nn'', ''\\rr'', ''\\tt'', ''\\vv'').  In addition, the escape
           sequences in _T_a_b_l_e _4_-_2_, _E_s_c_a_p_e _S_e_q_u_e_n_c_e_s _i_n _a_w_k shall be
           recognized. A <newline> shall not occur within a string constant. A
           string constant shall be terminated by the first unescaped
           occurrence of the character ''""'' after the one that begins the
           string constant. The value of the string shall be the sequence of
           all unescaped characters and values of escape sequences between,
           but not including, the two delimiting ''""'' characters.

        6. The token EERREE represents an extended regular expression constant.
           An ERE constant shall begin with the <slash> character. Within an
           ERE constant, a <backslash> character shall be considered to begin
           an escape sequence as specified in the table in the Base
           Definitions volume of POSIX.1-2017, _C_h_a_p_t_e_r _5, _F_i_l_e _F_o_r_m_a_t
           _N_o_t_a_t_i_o_n.  In addition, the escape sequences in _T_a_b_l_e _4_-_2_, _E_s_c_a_p_e
           _S_e_q_u_e_n_c_e_s _i_n _a_w_k shall be recognized. The application shall ensure
           that a <newline> does not occur within an ERE constant. An ERE
           constant shall be terminated by the first unescaped occurrence of
           the <slash> character after the one that begins the ERE constant.
           The extended regular expression represented by the ERE constant
           shall be the sequence of all unescaped characters and values of
           escape sequences between, but not including, the two delimiting
           <slash> characters.

        7. A <blank> shall have no effect, except to delimit lexical tokens or
           within SSTTRRIINNGG or EERREE tokens.

        8. The token NNUUMMBBEERR shall represent a numeric constant. Its form and
           numeric value shall either be equivalent to the ddeecciimmaall--ffllooaattiinngg--
           ccoonnssttaanntt token as specified by the ISO C standard, or it shall be a
           sequence of decimal digits and shall be evaluated as an integer
           constant in decimal. In addition, implementations may accept
           numeric constants with the form and numeric value equivalent to the
           hheexxaaddeecciimmaall--ccoonnssttaanntt and hheexxaaddeecciimmaall--ffllooaattiinngg--ccoonnssttaanntt tokens as
           specified by the ISO C standard.

           If the value is too large or too small to be representable (see
           _S_e_c_t_i_o_n _1_._1_._2, _C_o_n_c_e_p_t_s _D_e_r_i_v_e_d _f_r_o_m _t_h_e _I_S_O _C _S_t_a_n_d_a_r_d), the
           behavior is undefined.

        9. A sequence of underscores, digits, and alphabetics from the
           portable character set (see the Base Definitions volume of
           POSIX.1-2017, _S_e_c_t_i_o_n _6_._1, _P_o_r_t_a_b_l_e _C_h_a_r_a_c_t_e_r _S_e_t), beginning with
           an <underscore> or alphabetic character, shall be considered a
           word.

       10. The following words are keywords that shall be recognized as
           individual tokens; the name of the token is the same as the
           keyword:




           BBEEGGIINN      ddeelleettee     EENNDD        ffuunnccttiioonn   iinn         pprriinnttff
           bbrreeaakk      ddoo         eexxiitt       ggeettlliinnee    nneexxtt       rreettuurrnn
           ccoonnttiinnuuee   eellssee       ffoorr        iiff         pprriinntt      wwhhiillee

       11. The following words are names of built-in functions and shall be
           recognized as the token BBUUIILLTTIINN__FFUUNNCC__NNAAMMEE:

           aattaann22     ggssuubb      lloogg       sspplliitt     ssuubb       ttoouuppppeerr
           cclloossee     iinnddeexx     mmaattcchh     sspprriinnttff   ssuubbssttrr
           ccooss       iinntt       rraanndd      ssqqrrtt      ssyysstteemm
           eexxpp       lleennggtthh    ssiinn       ssrraanndd     ttoolloowweerr

           The above-listed keywords and names of built-in functions are
           considered reserved words.

       12. The token NNAAMMEE shall consist of a word that is not a keyword or a
           name of a built-in function and is not followed immediately
           (without any delimiters) by the ''(('' character.

       13. The token FFUUNNCC__NNAAMMEE shall consist of a word that is not a keyword
           or a name of a built-in function, followed immediately (without any
           delimiters) by the ''(('' character. The ''(('' character shall not be
           included as part of the token.

       14. The following two-character sequences shall be recognized as the
           named tokens:

                     +-----------+----------+------------+----------+
                     |TTookkeenn NNaammee | SSeeqquueennccee | TTookkeenn NNaammee | SSeeqquueennccee |
                     +-----------+----------+------------+----------+
                     |AADDDD__AASSSSIIGGNN |    +=    | NNOO__MMAATTCCHH   |    !~    |
                     |SSUUBB__AASSSSIIGGNN |    -=    | EEQQ         |    ==    |
                     |MMUULL__AASSSSIIGGNN |    *=    | LLEE         |    <=    |
                     |DDIIVV__AASSSSIIGGNN |    /=    | GGEE         |    >=    |
                     |MMOODD__AASSSSIIGGNN |    %=    | NNEE         |    !=    |
                     |PPOOWW__AASSSSIIGGNN |    ^=    | IINNCCRR       |    ++    |
                     |OORR         |    ||    | DDEECCRR       |    --    |
                     |AANNDD        |    &&    | AAPPPPEENNDD     |    >>    |
                     +-----------+----------+------------+----------+
       15. The following single characters shall be recognized as tokens whose
           names are the character:


               <newline> { } ( ) [ ] , ; + - * % ^ ! > < | ? : ~ $ =

       There is a lexical ambiguity between the token EERREE and the tokens ''//''
       and DDIIVV__AASSSSIIGGNN.  When an input sequence begins with a <slash> character
       in any syntactic context where the token ''//'' or DDIIVV__AASSSSIIGGNN could appear
       as the next token in a valid program, the longer of those two tokens
       that can be recognized shall be recognized. In any other syntactic
       context where the token EERREE could appear as the next token in a valid
       program, the token EERREE shall be recognized.

EEXXIITT SSTTAATTUUSS
       The following exit values shall be returned:

        0    All input files were processed successfully.

       >0    An error occurred.

       The exit status can be altered within the program by using an eexxiitt
       expression.

CCOONNSSEEQQUUEENNCCEESS OOFF EERRRROORRSS
       If any _f_i_l_e operand is specified and the named file cannot be accessed,
       _a_w_k shall write a diagnostic message to standard error and terminate
       without any further action.

       If the program specified by either the _p_r_o_g_r_a_m operand or a _p_r_o_g_f_i_l_e
       operand is not a valid _a_w_k program (as specified in the EXTENDED
       DESCRIPTION section), the behavior is undefined.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       The iinnddeexx, lleennggtthh, mmaattcchh, and ssuubbssttrr functions should not be confused
       with similar functions in the ISO C standard; the _a_w_k versions deal
       with characters, while the ISO C standard deals with bytes.

       Because the concatenation operation is represented by adjacent
       expressions rather than an explicit operator, it is often necessary to
       use parentheses to enforce the proper evaluation precedence.

       When using _a_w_k to process pathnames, it is recommended that LC_ALL, or
       at least LC_CTYPE and LC_COLLATE, are set to POSIX or C in the
       environment, since pathnames can contain byte sequences that do not
       form valid characters in some locales, in which case the utility's
       behavior would be undefined. In the POSIX locale each byte is a valid
       single-byte character, and therefore this problem is avoided.

       On implementations where the ""===="" operator checks if strings collate
       equally, applications needing to check whether strings are identical
       can use:


           length(a) == length(b) && index(a,b) == 1

       On implementations where the ""===="" operator checks if strings are
       identical, applications needing to check whether strings collate
       equally can use:


           a <= b && a >= b

EEXXAAMMPPLLEESS
       The _a_w_k program specified in the command line is most easily specified
       within single-quotes (for example, '_p_r_o_g_r_a_m') for applications using
       _s_h, because _a_w_k programs commonly contain characters that are special
       to the shell, including double-quotes. In the cases where an _a_w_k
       program contains single-quote characters, it is usually easiest to
       specify most of the program as strings within single-quotes
       concatenated by the shell with quoted single-quote characters. For
       example:


           awk '/'\''/ { print "quote:", $0 }'

       prints all lines from the standard input containing a single-quote
       character, prefixed with _q_u_o_t_e:.

       The following are examples of simple _a_w_k programs:

        1. Write to the standard output all input lines for which field 3 is
           greater than 5:


               $3 > 5

        2. Write every tenth line:


               (NR % 10) == 0

        3. Write any line with a substring matching the regular expression:


               /(G|D)(2[0-9][[:alpha:]]*)/

        4. Print any line with a substring containing a ''GG'' or ''DD'', followed
           by a sequence of digits and characters. This example uses character
           classes ddiiggiitt and aallpphhaa to match language-independent digit and
           alphabetic characters respectively:


               /(G|D)([[:digit:][:alpha:]]*)/

        5. Write any line in which the second field matches the regular
           expression and the fourth field does not:


               $2 ~ /xyz/ && $4 !~ /xyz/

        6. Write any line in which the second field contains a <backslash>:


               $2 ~ /\\/

        7. Write any line in which the second field contains a <backslash>.
           Note that <backslash>-escapes are interpreted twice; once in
           lexical processing of the string and once in processing the regular
           expression:


               $2 ~ "\\\\"

        8. Write the second to the last and the last field in each line.
           Separate the fields by a <colon>:


               {OFS=":";print $(NF-1), $NF}

        9. Write the line number and number of fields in each line. The three
           strings representing the line number, the <colon>, and the number
           of fields are concatenated and that string is written to standard
           output:


               {print NR ":" NF}

       10. Write lines longer than 72 characters:


               length($0) > 72

       11. Write the first two fields in opposite order separated by OOFFSS:


               { print $2, $1 }

       12. Same, with input fields separated by a <comma> or <space> and <tab>
           characters, or both:


               BEGIN { FS = ",[ \t]*|[ \t]+" }
                     { print $2, $1 }

       13. Add up the first column, print sum, and average:


                     {s += $1 }
               END   {print "sum is ", s, " average is", s/NR}

       14. Write fields in reverse order, one per line (many lines out for
           each line in):


               { for (i = NF; i > 0; --i) print $i }

       15. Write all lines between occurrences of the strings ssttaarrtt and ssttoopp:


               /start/, /stop/

       16. Write all lines whose first field is different from the previous
           one:


               $1 != prev { print; prev = $1 }

       17. Simulate _e_c_h_o:


               BEGIN  {
                       for (i = 1; i < ARGC; ++i)
                       printf("%s%s", ARGV[i], i==ARGC-1?"\n":" ")
               }

       18. Write the path prefixes contained in the _P_A_T_H environment variable,
           one per line:


               BEGIN  {
                       n = split (ENVIRON["PATH"], path, ":")
                       for (i = 1; i <= n; ++i)
                       print path[i]
               }

       19. If there is a file named iinnppuutt containing page headers of the form:
           Page #

           and a file named pprrooggrraamm that contains:


               /Page/   { $2 = n++; }
                        { print }

           then the command line:


               awk -f program n=5 input

           prints the file iinnppuutt, filling in page numbers starting at 5.

RRAATTIIOONNAALLEE
       This description is based on the new _a_w_k, ``nawk'', (see the referenced
       _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), which introduced a number of new
       features to the historical _a_w_k:

        1. New keywords: ddeelleettee, ddoo, ffuunnccttiioonn, rreettuurrnn

        2. New built-in functions: aattaann22, cclloossee, ccooss, ggssuubb, mmaattcchh, rraanndd, ssiinn,
           ssrraanndd, ssuubb, ssyysstteemm

        3. New predefined variables: FFNNRR, AARRGGCC, AARRGGVV, RRSSTTAARRTT, RRLLEENNGGTTHH, SSUUBBSSEEPP

        4. New expression operators: ??, ::, ,,, ^^

        5. The FFSS variable and the third argument to sspplliitt, now treated as
           extended regular expressions.

        6. The operator precedence, changed to more closely match the C
           language.  Two examples of code that operate differently are:


               while ( n /= 10 > 1) ...
               if (!"wk" ~ /bwk/) ...

       Several features have been added based on newer implementations of _a_w_k:

        *  Multiple instances of --ff _p_r_o_g_f_i_l_e are permitted.

        *  The new option --vv _a_s_s_i_g_n_m_e_n_t_.

        *  The new predefined variable EENNVVIIRROONN.

        *  New built-in functions ttoouuppppeerr and ttoolloowweerr.

        *  More formatting capabilities are added to pprriinnttff to match the ISO C
           standard.

       Earlier versions of this standard required implementations to support
       multiple adjacent <semicolon>s, lines with one or more <semicolon>
       before a rule (_p_a_t_t_e_r_n_-_a_c_t_i_o_n pairs), and lines with only
       <semicolon>(s).  These are not required by this standard and are
       considered poor programming practice, but can be accepted by an
       implementation of _a_w_k as an extension.

       The overall _a_w_k syntax has always been based on the C language, with a
       few features from the shell command language and other sources. Because
       of this, it is not completely compatible with any other language, which
       has caused confusion for some users. It is not the intent of the
       standard developers to address such issues. A few relatively minor
       changes toward making the language more compatible with the ISO C
       standard were made; most of these changes are based on similar changes
       in recent implementations, as described above. There remain several C-
       language conventions that are not in _a_w_k.  One of the notable ones is
       the <comma> operator, which is commonly used to specify multiple
       expressions in the C language ffoorr statement. Also, there are various
       places where _a_w_k is more restrictive than the C language regarding the
       type of expression that can be used in a given context. These
       limitations are due to the different features that the _a_w_k language
       does provide.

       Regular expressions in _a_w_k have been extended somewhat from historical
       implementations to make them a pure superset of extended regular
       expressions, as defined by POSIX.1-2008 (see the Base Definitions
       volume of POSIX.1-2017, _S_e_c_t_i_o_n _9_._4, _E_x_t_e_n_d_e_d _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s).
       The main extensions are internationalization features and interval
       expressions. Historical implementations of _a_w_k have long supported
       <backslash>-escape sequences as an extension to extended regular
       expressions, and this extension has been retained despite inconsistency
       with other utilities. The number of escape sequences recognized in both
       extended regular expressions and strings has varied (generally
       increasing with time) among implementations. The set specified by
       POSIX.1-2008 includes most sequences known to be supported by popular
       implementations and by the ISO C standard. One sequence that is not
       supported is hexadecimal value escapes beginning with ''\\xx''.  This would
       allow values expressed in more than 9 bits to be used within _a_w_k as in
       the ISO C standard. However, because this syntax has a non-
       deterministic length, it does not permit the subsequent character to be
       a hexadecimal digit. This limitation can be dealt with in the C
       language by the use of lexical string concatenation. In the _a_w_k
       language, concatenation could also be a solution for strings, but not
       for extended regular expressions (either lexical ERE tokens or strings
       used dynamically as regular expressions). Because of this limitation,
       the feature has not been added to POSIX.1-2008.

       When a string variable is used in a context where an extended regular
       expression normally appears (where the lexical token ERE is used in the
       grammar) the string does not contain the literal <slash> characters.

       Some versions of _a_w_k allow the form:


           func name(args, ... ) { statements }

       This has been deprecated by the authors of the language, who asked that
       it not be specified.

       Historical implementations of _a_w_k produce an error if a nneexxtt statement
       is executed in a BBEEGGIINN action, and cause _a_w_k to terminate if a nneexxtt
       statement is executed in an EENNDD action. This behavior has not been
       documented, and it was not believed that it was necessary to
       standardize it.

       The specification of conversions between string and numeric values is
       much more detailed than in the documentation of historical
       implementations or in the referenced _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.
       Although most of the behavior is designed to be intuitive, the details
       are necessary to ensure compatible behavior from different
       implementations. This is especially important in relational expressions
       since the types of the operands determine whether a string or numeric
       comparison is performed. From the perspective of an application
       developer, it is usually sufficient to expect intuitive behavior and to
       force conversions (by adding zero or concatenating a null string) when
       the type of an expression does not obviously match what is needed. The
       intent has been to specify historical practice in almost all cases. The
       one exception is that, in historical implementations, variables and
       constants maintain both string and numeric values after their original
       value is converted by any use. This means that referencing a variable
       or constant can have unexpected side-effects. For example, with
       historical implementations the following program:


           {
               a = "+2"
               b = 2
               if (NR % 2)
                   c = a + b
               if (a == b)
                   print "numeric comparison"
               else
                   print "string comparison"
           }

       would perform a numeric comparison (and output numeric comparison) for
       each odd-numbered line, but perform a string comparison (and output
       string comparison) for each even-numbered line. POSIX.1-2008 ensures
       that comparisons will be numeric if necessary. With historical
       implementations, the following program:


           BEGIN {
               OFMT = "%e"
               print 3.14
               OFMT = "%f"
               print 3.14
           }

       would output ""33..114400000000ee++0000"" twice, because in the second pprriinntt
       statement the constant ""33..1144"" would have a string value from the
       previous conversion. POSIX.1-2008 requires that the output of the
       second pprriinntt statement be ""33..114400000000"".  The behavior of historical
       implementations was seen as too unintuitive and unpredictable.

       It was pointed out that with the rules contained in early drafts, the
       following script would print nothing:


           BEGIN {
               y[1.5] = 1
               OFMT = "%e"
               print y[1.5]
           }

       Therefore, a new variable, CCOONNVVFFMMTT, was introduced. The OOFFMMTT variable
       is now restricted to affecting output conversions of numbers to strings
       and CCOONNVVFFMMTT is used for internal conversions, such as comparisons or
       array indexing. The default value is the same as that for OOFFMMTT, so
       unless a program changes CCOONNVVFFMMTT (which no historical program would
       do), it will receive the historical behavior associated with internal
       string conversions.

       The POSIX _a_w_k lexical and syntactic conventions are specified more
       formally than in other sources. Again the intent has been to specify
       historical practice. One convention that may not be obvious from the
       formal grammar as in other verbal descriptions is where <newline>
       characters are acceptable. There are several obvious placements such as
       terminating a statement, and a <backslash> can be used to escape
       <newline> characters between any lexical tokens. In addition, <newline>
       characters without <backslash> characters can follow a comma, an open
       brace, a logical AND operator (""&&&&""), a logical OR operator (""||||""), the
       ddoo keyword, the eellssee keyword, and the closing parenthesis of an iiff,
       ffoorr, or wwhhiillee statement. For example:


           { print $1,
                   $2 }

       The requirement that _a_w_k add a trailing <newline> to the program
       argument text is to simplify the grammar, making it match a text file
       in form. There is no way for an application or test suite to determine
       whether a literal <newline> is added or whether _a_w_k simply acts as if
       it did.

       POSIX.1-2008 requires several changes from historical implementations
       in order to support internationalization. Probably the most subtle of
       these is the use of the decimal-point character, defined by the
       _L_C___N_U_M_E_R_I_C category of the locale, in representations of floating-point
       numbers.  This locale-specific character is used in recognizing numeric
       input, in converting between strings and numeric values, and in
       formatting output. However, regardless of locale, the <period>
       character (the decimal-point character of the POSIX locale) is the
       decimal-point character recognized in processing _a_w_k programs
       (including assignments in command line arguments). This is essentially
       the same convention as the one used in the ISO C standard. The
       difference is that the C language includes the _s_e_t_l_o_c_a_l_e() function,
       which permits an application to modify its locale. Because of this
       capability, a C application begins executing with its locale set to the
       C locale, and only executes in the environment-specified locale after
       an explicit call to _s_e_t_l_o_c_a_l_e().  However, adding such an elaborate new
       feature to the _a_w_k language was seen as inappropriate for POSIX.1-2008.
       It is possible to execute an _a_w_k program explicitly in any desired
       locale by setting the environment in the shell.

       The undefined behavior resulting from NULs in extended regular
       expressions allows future extensions for the GNU _g_a_w_k program to
       process binary data.

       The behavior in the case of invalid _a_w_k programs (including lexical,
       syntactic, and semantic errors) is undefined because it was considered
       overly limiting on implementations to specify. In most cases such
       errors can be expected to produce a diagnostic and a non-zero exit
       status. However, some implementations may choose to extend the language
       in ways that make use of certain invalid constructs. Other invalid
       constructs might be deemed worthy of a warning, but otherwise cause
       some reasonable behavior. Still other constructs may be very difficult
       to detect in some implementations.  Also, different implementations
       might detect a given error during an initial parsing of the program
       (before reading any input files) while others might detect it when
       executing the program after reading some input. Implementors should be
       aware that diagnosing errors as early as possible and producing useful
       diagnostics can ease debugging of applications, and thus make an
       implementation more usable.

       The unspecified behavior from using multi-character RRSS values is to
       allow possible future extensions based on extended regular expressions
       used for record separators. Historical implementations take the first
       character of the string and ignore the others.

       Unspecified behavior when _s_p_l_i_t(_s_t_r_i_n_g,_a_r_r_a_y,<null>) is used is to
       allow a proposed future extension that would split up a string into an
       array of individual characters.

       In the context of the ggeettlliinnee function, equally good arguments for
       different precedences of the || and << operators can be made. Historical
       practice has been that:


           getline < "a" "b"

       is parsed as:


           ( getline < "a" ) "b"

       although many would argue that the intent was that the file aabb should
       be read. However:


           getline < "x" + 1

       parses as:


           getline < ( "x" + 1 )

       Similar problems occur with the || version of ggeettlliinnee, particularly in
       combination with $$.  For example:


           $"echo hi" | getline

       (This situation is particularly problematic when used in a pprriinntt
       statement, where the ||ggeettlliinnee part might be a redirection of the
       pprriinntt.)

       Since in most cases such constructs are not (or at least should not) be
       used (because they have a natural ambiguity for which there is no
       conventional parsing), the meaning of these constructs has been made
       explicitly unspecified. (The effect is that a conforming application
       that runs into the problem must parenthesize to resolve the ambiguity.)
       There appeared to be few if any actual uses of such constructs.

       Grammars can be written that would cause an error under these
       circumstances. Where backwards-compatibility is not a large
       consideration, implementors may wish to use such grammars.

       Some historical implementations have allowed some built-in functions to
       be called without an argument list, the result being a default argument
       list chosen in some ``reasonable'' way. Use of lleennggtthh as a synonym for
       lleennggtthh(($$00)) is the only one of these forms that is thought to be widely
       known or widely used; this particular form is documented in various
       places (for example, most historical _a_w_k reference pages, although not
       in the referenced _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) as legitimate practice.
       With this exception, default argument lists have always been
       undocumented and vaguely defined, and it is not at all clear how (or
       if) they should be generalized to user-defined functions. They add no
       useful functionality and preclude possible future extensions that might
       need to name functions without calling them. Not standardizing them
       seems the simplest course. The standard developers considered that
       lleennggtthh merited special treatment, however, since it has been documented
       in the past and sees possibly substantial use in historical programs.
       Accordingly, this usage has been made legitimate, but Issue 5 removed
       the obsolescent marking for XSI-conforming implementations and many
       otherwise conforming applications depend on this feature.

       In ssuubb and ggssuubb, if _r_e_p_l is a string literal (the lexical token
       SSTTRRIINNGG), then two consecutive <backslash> characters should be used in
       the string to ensure a single <backslash> will precede the <ampersand>
       when the resultant string is passed to the function. (For example, to
       specify one literal <ampersand> in the replacement string, use
       ggssuubb(EERREE, ""\\\\&&"").)

       Historically, the only special character in the _r_e_p_l argument of ssuubb
       and ggssuubb string functions was the <ampersand> (''&&'') character and
       preceding it with the <backslash> character was used to turn off its
       special meaning.

       The description in the ISO POSIX-2:1993 standard introduced behavior
       such that the <backslash> character was another special character and
       it was unspecified whether there were any other special characters.
       This description introduced several portability problems, some of which
       are described below, and so it has been replaced with the more
       historical description. Some of the problems include:

        *  Historically, to create the replacement string, a script could use
           ggssuubb(EERREE, ""\\\\&&""), but with the ISO POSIX-2:1993 standard wording,
           it was necessary to use ggssuubb(EERREE, ""\\\\\\\\&&"").  The <backslash>
           characters are doubled here because all string literals are subject
           to lexical analysis, which would reduce each pair of <backslash>
           characters to a single <backslash> before being passed to ggssuubb.

        *  Since it was unspecified what the special characters were, for
           portable scripts to guarantee that characters are printed
           literally, each character had to be preceded with a <backslash>.
           (For example, a portable script had to use ggssuubb(EERREE, ""\\\\hh\\\\ii"") to
           produce a replacement string of ""hhii"".)

       The description for comparisons in the ISO POSIX-2:1993 standard did
       not properly describe historical practice because of the way numeric
       strings are compared as numbers. The current rules cause the following
       code:


           if (0 == "000")
               print "strange, but true"
           else
               print "not true"

       to do a numeric comparison, causing the iiff to succeed. It should be
       intuitively obvious that this is incorrect behavior, and indeed, no
       historical implementation of _a_w_k actually behaves this way.

       To fix this problem, the definition of _n_u_m_e_r_i_c _s_t_r_i_n_g was enhanced to
       include only those values obtained from specific circumstances (mostly
       external sources) where it is not possible to determine unambiguously
       whether the value is intended to be a string or a numeric.

       Variables that are assigned to a numeric string shall also be treated
       as a numeric string. (For example, the notion of a numeric string can
       be propagated across assignments.) In comparisons, all variables having
       the uninitialized value are to be treated as a numeric operand
       evaluating to the numeric value zero.

       Uninitialized variables include all types of variables including
       scalars, array elements, and fields. The definition of an uninitialized
       value in _V_a_r_i_a_b_l_e_s _a_n_d _S_p_e_c_i_a_l _V_a_r_i_a_b_l_e_s is necessary to describe the
       value placed on uninitialized variables and on fields that are valid
       (for example, << $$NNFF) but have no characters in them and to describe how
       these variables are to be used in comparisons. A valid field, such as
       $$11, that has no characters in it can be obtained from an input line of
       ""\\tt\\tt"" when FFSS==''\\tt''.  Historically, the comparison ($$11<<10) was done
       numerically after evaluating $$11 to the value zero.

       The phrase ``... also shall have the numeric value of the numeric
       string'' was removed from several sections of the ISO POSIX-2:1993
       standard because is specifies an unnecessary implementation detail. It
       is not necessary for POSIX.1-2008 to specify that these objects be
       assigned two different values.  It is only necessary to specify that
       these objects may evaluate to two different values depending on
       context.

       Historical implementations of _a_w_k did not parse hexadecimal integer or
       floating constants like ""00xxaa"" and ""00xxaapp00"".  Due to an oversight, the
       2001 through 2004 editions of this standard required support for
       hexadecimal floating constants. This was due to the reference to
       _a_t_o_f().  This version of the standard allows but does not require
       implementations to use _a_t_o_f() and includes a description of how
       floating-point numbers are recognized as an alternative to match
       historic behavior. The intent of this change is to allow
       implementations to recognize floating-point constants according to
       either the ISO/IEC 9899:1990 standard or ISO/IEC 9899:1999 standard,
       and to allow (but not require) implementations to recognize hexadecimal
       integer constants.

       Historical implementations of _a_w_k did not support floating-point
       infinities and NaNs in _n_u_m_e_r_i_c _s_t_r_i_n_g_s; e.g., ""--IINNFF"" and ""NNaaNN"".
       However, implementations that use the _a_t_o_f() or _s_t_r_t_o_d() functions to
       do the conversion picked up support for these values if they used a
       ISO/IEC 9899:1999 standard version of the function instead of a
       ISO/IEC 9899:1990 standard version. Due to an oversight, the 2001
       through 2004 editions of this standard did not allow support for
       infinities and NaNs, but in this revision support is allowed (but not
       required). This is a silent change to the behavior of _a_w_k programs; for
       example, in the POSIX locale the expression:


           ("-INF" + 0 < 0)

       formerly had the value 0 because ""--IINNFF"" converted to 0, but now it may
       have the value 0 or 1.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       A future version of this standard may require the ""!!=="" and ""====""
       operators to perform string comparisons by checking if the strings are
       identical (and not by checking if they collate equally).

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _1_._3, _G_r_a_m_m_a_r _C_o_n_v_e_n_t_i_o_n_s, _g_r_e_p, _l_e_x, _s_e_d

       The Base Definitions volume of POSIX.1-2017, _C_h_a_p_t_e_r _5, _F_i_l_e _F_o_r_m_a_t
       _N_o_t_a_t_i_o_n, _S_e_c_t_i_o_n _6_._1, _P_o_r_t_a_b_l_e _C_h_a_r_a_c_t_e_r _S_e_t, _C_h_a_p_t_e_r _8, _E_n_v_i_r_o_n_m_e_n_t
       _V_a_r_i_a_b_l_e_s, _C_h_a_p_t_e_r _9, _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x
       _G_u_i_d_e_l_i_n_e_s

       The System Interfaces volume of POSIX.1-2017, _a_t_o_f(), _e_x_e_c, _i_s_s_p_a_c_e(),
       _p_o_p_e_n(), _s_e_t_l_o_c_a_l_e(), _s_t_r_t_o_d()

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  In the event of any discrepancy between this version and the
       original IEEE and The Open Group Standard, the original IEEE and The
       Open Group Standard is the referee document. The original Standard can
       be obtained online at http://www.opengroup.org/unix/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                               AWK(1)
