The `nextfile' Statement
`gawk' provides the `nextfile' statement, which is similar to the
`next' statement. However, instead of abandoning processing of the
current record, the `nextfile' statement instructs `gawk' to stop
processing the current data file.
Upon execution of the `nextfile' statement, `FILENAME' is updated to
the name of the next data file listed on the command line, `FNR' is
reset to one, `ARGIND' is incremented, and processing starts over with
the first rule in the progam. Note: Built-in Variables.
If the `nextfile' statement causes the end of the input to be
reached, then the code in any `END' rules will be executed. Note: The
`BEGIN' and `END' Special Patterns.
The `nextfile' statement is a `gawk' extension; it is not
(currently) available in any other `awk' implementation. Note:
Implementing `nextfile' as a Function, for a
user-defined function you can use to simulate the `nextfile' statement.
The `nextfile' statement would be useful if you have many data files
to process, and you expect that you would not want to process every
record in every file. Normally, in order to move on to the next data
file, you would have to continue scanning the unwanted records. The
`nextfile' statement accomplishes this much more efficiently.
*Caution:* Versions of `gawk' prior to 3.0 used two words (`next
file') for the `nextfile' statement. This was changed in 3.0 to one
word, since the treatment of `file' was inconsistent. When it appeared
after `next', it was a keyword. Otherwise, it was a regular
identifier. The old usage is still accepted. However, `gawk' will
generate a warning message, and support for `next file' will eventually
be discontinued in a future version of `gawk'.
Next: Exit Statement Prev: Next Statement Up: Statements
[ Dokumentation lokal installierter Software ]