GNU Info

Info Node: (gawk.info)Getline

(gawk.info)Getline


Prev: Multiple Line Up: Reading Files
Enter node , (file) or (file)node

Explicit Input with `getline'
=============================

   So far we have been getting our input data from `awk''s main input
stream--either the standard input (usually your terminal, sometimes the
output from another program) or from the files specified on the command
line.  The `awk' language has a special built-in command called
`getline' that can be used to read input under your explicit control.

   The `getline' command is used in several different ways and should
_not_ be used by beginners.  The examples that follow the explanation
of the `getline' command include material that has not been covered
yet.  Therefore, come back and study the `getline' command _after_ you
have reviewed the rest of this Info file and have a good knowledge of
how `awk' works.

   The `getline' command returns one if it finds a record and zero if
the end of the file is encountered.  If there is some error in getting
a record, such as a file that cannot be opened, then `getline' returns
-1.  In this case, `gawk' sets the variable `ERRNO' to a string
describing the error that occurred.

   In the following examples, COMMAND stands for a string value that
represents a shell command.

Plain Getline
Using `getline' with no arguments.
Getline/Variable
Using `getline' into a variable.
Getline/File
Using `getline' from a file.
Getline/Variable/File
Using `getline' into a variable from a
file.
Getline/Pipe
Using `getline' from a pipe.
Getline/Variable/Pipe
Using `getline' into a variable from a
pipe.
Getline/Coprocess
Using `getline' from a coprocess.
Getline/Variable/Coprocess
Using `getline' into a variable from a
coprocess.
Getline Notes
Important things to know about `getline'.
Getline Summary
Summary of `getline' Variants.

automatically generated by info2www version 1.2.2.9