is similar to the
However, instead of abandoning processing of the current record, the
nextfile statement instructs
awk to stop processing the
current data file.
Upon execution of the
updated to the name of the next data file listed on the command line,
FNR is reset to one,
starts over with the first rule in the program.
nextfile statement causes the end of the input to be reached,
then the code in any
END rules is executed. An exception to this is
nextfile is invoked during execution of any statement in an
END rule; in this case, it causes the program to stop immediately.
See section The
END Special Patterns.
nextfile statement is useful when there are many data files
to process but it isn’t necessary to process every record in every file.
in order to move on to the next data file, a program
would have to continue scanning the unwanted records. The
statement accomplishes this much more efficiently.
gawk, execution of
nextfile causes additional things
to happen: any
ENDFILE rules are executed if
not currently in an
incremented, and any
BEGINFILE rules are executed. (
hasn’t been introduced yet. See section Predefined Variables.)
nextfile is useful inside a
rule to skip over a file that would otherwise cause
to exit with a fatal error. In this case,
ENDFILE rules are not
executed. See section The
ENDFILE Special Patterns.
Although it might seem that ‘close(FILENAME)’ would accomplish
the same as
nextfile, this isn’t true.
reserved for closing files, pipes, and coprocesses that are
opened with redirections. It is not related to the main processing that
awk does with the files listed in
NOTE: For many years,
nextfilewas a common extension. In September 2012, it was accepted for inclusion into the POSIX standard. See the Austin Group website.
The current version of BWK
nextfile. However, they don’t allow the
nextfile statement inside function bodies (see section User-Defined Functions).
gawk does; a
nextfile inside a function body reads the
first record from the next file and starts processing it with the first
rule in the program, just as any other