O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The nextfile() function

The nextfile() function is similar to the next statement function in the sense that it instructs AWK to stop processing the current input file. Upon execution of the nextfile statement, the filename built-in variable is updated and FNR is reset. The processing restarts with the first rule in the program, except in the case of nextfile being invoked in END rule.

This is useful when we have multiple files to process, but you don't have to process each record of every file. Without the nextfile statement to move from one file to another, a program would have to go through all the records of the current input file. The following example illustrates how the nextfile statement works:

$ awk '{ if ($1 ~/Eva/) nextfile; print ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required