MPE/iX Shell and Utilities Reference Manual, Vol 1

awk(1) MPE/iX Shell and Utilities awk(1)
Field specifiers have the form $n where n runs from 1 through NF. Such a field specifier
refers to the nth field of the current input record. $0 (zero) refers to the entire current input
record.
The getline function can read a value for a variable or $0 from the current input, from a
file, or from a pipe. The result of getline is an integer indicating whether the read opera-
tion was successful. A value of 1 indicates success; 0 indicates end-of-file encountered; and
-1 indicates that an error occurred. Possible forms for getline are:
getline
reads next input record into $0 and splits the record into fields. NF, NR, and FNR are
set appropriately.
getline var
reads next input record into the variable var. awk does not split the record into fields
(which means that the current $n values do not change), but sets NR and FNR appro-
priately.
getline <expr
interprets the string value of expr to be a file name. awk reads the next record from
that file into $0, splits it into fields, and sets NF appropriately. If the file is not open,
awk opens it. The file remains open until you close it with a close function.
getline var <expr
interprets the string value of expr to be a file name, and reads the next record from
that file into the variable var, but does not split it into fields.
expr | getline
interprets the string value of expr as a command line to be run. awk pipes output
from this command into getline, and reads it into $0 in a manner similar to
getline <expr. See the System Function section for additional details.
expr | getline var
runs the string value of expr as a command and pipes the output of the command into
getline. The result is similar to getline var <expr.
You can only have a limited number of files and pipes open at one time. You can close files
and pipes during execution using the
close(expr)
function. The expr must be one that came before | or after < in getline, or after > or >> in
print or printf. For a description of print and printf, see the Output section. If the
function successfully closes the pipe, it returns zero. By closing files and pipes that you no
longer need, you can use any number of files and pipes in the course of running an awk pro-
gram.
Commands and Utilities 1-25