Open System Services Shell and Utilities Reference Manual (G06.27+, H06.04+)
User Commands (m - o) nawk(1)
Variables
Variables can be scalars, array elements (denoted x[i]),orfields.
Variable names can consist of uppercase and lowercase alphabetic letters, the underscore charac-
ter, the digits (0 to 9), and extended characters. Variable names cannot begin with a digit.
Variables are initialized to the null string. Array subscripts can be any string; they do not have to
be numeric. This approach allows for a form of associative memory. Enclose string constants in
expressions in "" (double quotes). Multiple subscripts such as [i,j,k] are permitted; the consti-
tuents are concatenated and separated by the value of SUBSEP (see the description in the fol-
lowing list).
There are several variables with special meaning to nawk. They include:
ARGC Argument count, assignable.
ARGV Argument array, assignable; nonnull members are interpreted as filenames.
FS Input field separator (default is a space). If it is a space, then any number of spaces and
tabs can separate fields.
NF The number of fields in the current input line (record), with a limit of 99.
NR The number of the current input line (record).
FNR The number of the current input line (record) in the current file.
FILENAME
The name of the current input file.
RS Input record separator (default is a newline character).
OFS The output field separator (default is a space).
ORS The output record separator (default is a newline character).
OFMT The output format for numbers (default % .6g).
SUBSEP
Separates multiple subscripts (default is 031).
Functions
Functions are defined at the position of a pattern-action statement, as follows:
function foo(a, b, c) { ... ; return x }
Arguments are passed by value if scalar and by reference if array name; functions can be called
recursively. Arguments are local to the function; all other variables are global.
There are several built-in functions that can be used in nawk actions. (For information about
regular expressions as referred to in this subsection, see the grep(1) reference page.)
length(argument)
Returns the length, in characters, of argument, or of the entire line if there is no argu-
ment.
blength(argument)
Returns the length, in bytes, of argument, or of the entire line if there is no argument.
527188-004 Hewlett-Packard Company 6−31