GNU Info

Info Node: (gawk.info)Getline/File

(gawk.info)Getline/File


Next: Getline/Variable/File Prev: Getline/Variable Up: Getline
Enter node , (file) or (file)node

Using `getline' from a File
---------------------------

   Use `getline < FILE' to read the next record from FILE.  Here FILE
is a string-valued expression that specifies the file name.  `< FILE'
is called a "redirection" because 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:

     {
         if ($1 == 10) {
              getline < "secondary.input"
              print
         } else
              print
     }

   Because the main input stream is not used, the values of `NR' and
`FNR' are not changed. However, the record it reads is split into
fields in the normal manner, so the values of `$0' and the other fields
are changed, resulting in a new 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.  You should write it as
`getline < (dir "/" file)' if you want your program to be portable to
other `awk' implementations.  (It happens that `gawk' gets it right,
but you should not rely on this. Parentheses make it easier to read.)


automatically generated by info2www version 1.2.2.9