getline
Variants
With all the forms of getline
, even though $0
and NF
,
may be updated, the record will not be tested against all the patterns
in the awk
program, in the way that would happen if the record
were read normally by the main processing loop of awk
. However
the new record is tested against any subsequent rules.
Many awk
implementations limit the number of pipelines an awk
program may have open to just one! In gawk
, there is no such limit.
You can open as many pipelines as the underlying operating system will
permit.
An interesting side-effect occurs if you use getline
(without a
redirection) inside a BEGIN
rule. Since an unredirected getline
reads from the command line data files, the first getline
command
causes awk
to set the value of FILENAME
. Normally,
FILENAME
does not have a value inside BEGIN
rules, since you
have not yet started to process the command line data files (d.c.).
(See section The BEGIN
and END
Special Patterns,
also see section Built-in Variables that Convey Information.)
The following table summarizes the six variants of getline
,
listing which built-in variables are set by each one.
getline
$0
, NF
, FNR
, and NR
.
getline var
FNR
, and NR
.
getline < file
$0
, and NF
.
getline var < file
command | getline
$0
, and NF
.
command | getline var
Go to the first, previous, next, last section, table of contents.