DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(gawk.info.gz) Getline/Variable/File

Info Catalog (gawk.info.gz) Getline/File (gawk.info.gz) Getline (gawk.info.gz) Getline/Pipe
 
 Using `getline' into a Variable from a File
 -------------------------------------------
 
    Use `getline VAR < FILE' to read input from the file FILE, and put
 it in the variable VAR.  As above, FILE is a string-valued expression
 that specifies the file from which to read.
 
    In this version of `getline', none of the built-in variables are
 changed and the record is not split into fields.  The only variable
 changed is VAR.  For example, the following program copies all the
 input files to the output, except for records that say
 `@include FILENAME'.  Such a record is replaced by the contents of the
 file FILENAME:
 
      {
           if (NF == 2 && $1 == "@include") {
                while ((getline line < $2) > 0)
                     print line
                close($2)
           } else
                print
      }
 
    Note here how the name of the extra input file is not built into the
 program; it is taken directly from the data, specifically from the
 second field on the `@include' line.
 
    The `close' function is called to ensure that if two identical
 `@include' lines appear in the input, the entire specified file is
 included twice.   Closing Input and Output Redirections Close
 Files And Pipes.
 
    One deficiency of this program is that it does not process nested
 `@include' statements (i.e., `@include' statements in included files)
 the way a true macro preprocessor would.   An Easy Way to Use
 Library Functions Igawk Program, for a program that does handle nested
 `@include' statements.
 
Info Catalog (gawk.info.gz) Getline/File (gawk.info.gz) Getline (gawk.info.gz) Getline/Pipe
automatically generated byinfo2html