So far we have been getting our input data from
input stream—either the standard input (usually your keyboard, sometimes
the output from another program) or the
files specified on the command line. The
awk language has a
special built-in command called
can be used to read input under your explicit control.
getline command is used in several different ways and should
not be used by beginners.
The examples that follow the explanation of the
include material that has not been covered yet. Therefore, come back
and study the
getline command after you have reviewed the
this Web page
and have a good knowledge of how
getline command returns 1 if it finds a record and 0 if
it encounters the end of the file. If there is some error in getting
a record, such as a file that cannot be opened, then
returns -1. In this case,
gawk sets the variable
ERRNO to a string describing the error that occurred.
ERRNO indicates that the I/O operation may be
PROCINFO["input", "RETRY"] is set,
getline returns -2
instead of -1, and further calls to
may be attempted. See Retrying Input for further information about
In the following examples, command stands for a string value that represents a shell command.
NOTE: When --sandbox is specified (see Options), reading lines from files, pipes, and coprocesses is disabled.
|• Plain Getline:||Using |
|• Getline/Variable:||Using |
|• Getline/File:||Using |
|• Getline/Variable/File:||Using |
|• Getline/Pipe:||Using |
|• Getline/Variable/Pipe:||Using |
|• Getline/Coprocess:||Using |
|• Getline/Variable/Coprocess:||Using |
|• Getline Notes:||Important things to know about |
|• Getline Summary:||Summary of |