getline
from a FileUse `getline < file' to read the next record from the file file. Here file is a string-valued expression that specifies the file name. `< file' is called a redirection since it directs input to come from a different place.
For example, the following program reads its input record from the file `secondary.input' when it encounters a first field with a value equal to 10 in the current input file.
awk '{ if ($1 == 10) { getline < "secondary.input" print } else print }'
Since the main input stream is not used, the values of NR
and
FNR
are not changed. But the record read is split into fields in
the normal manner, so the values of $0
and other fields are
changed. So is the value of NF
.
According to POSIX, `getline < expression' is ambiguous if
expression contains unparenthesized operators other than
`$'; for example, `getline < dir "/" file' is ambiguous
because the concatenation operator is not parenthesized, and you should
write it as `getline < (dir "/" file)' if you want your program
to be portable to other awk
implementations.
Go to the first, previous, next, last section, table of contents.