MPE/iX Shell and Utilities Reference Manual, Vol 1

awk(1) MPE/iX Shell and Utilities awk(1)
Variables and Expressions
There are three types of variables in awk: identifiers, fields, and array elements.
An identifier is a sequence of letters, digits, and underscores beginning with a letter or an
underscore.
For a description of fields, see the Input subsection.
Arrays are associative collections of values called the elements of the array. Constructs of the
form,
identifier[subscript]
where subscript has the form expr or expr,expr,...., reference array elements. Each such expr
can have any string value. For multiple expr subscripts, awk concatenates the string values of
all exprs with a separate character SUBSEP between each. The initial value of SUBSEP is set
to \034 (
ASCII field separator).
We sometimes refer to fields and identifiers as scalar variables to distinguish them from
arrays.
You do not declare awk variables and you do not need to initialize them. The value of an
uninitialized variable is the empty string in a string context and the number 0 in a numeric
context.
Expressions consist of constants, variables, functions, regular expressions and subscript in
array conditions (described later) combined with operators. Each variable and expression has
a string value and a corresponding numeric value; awk uses the value appropriate to the con-
text.
When converting a numeric value to its corresponding string value, awk performs the equiva-
lent of a call to the sprintf function (see Built-in String Functions) where the one and only
expr argument is the numeric value and the fmt argument is either %d (if the numeric value is
an integer) or the value of the variable CONVFMT (if the numeric value is not an integer). The
default value of CONVFMT is %.6g. If you use a string in a numeric context, and awk cannot
interpret the contents of the string as a number, it treats the value of the string as zero.
Numeric constants are sequences of decimal digits.
String constants are quoted, as in "a literal string". Literal strings can contain the
escape sequences shown in Table 1-1, Escape Sequences in awk Literal Strings.
Commands and Utilities 1-19