Awk – Is Awk’s Nextfile Specified in POSIX?

awkposix

GNU awk manual on nextfile reads:

NOTE: For many years, nextfile was a common extension. In September 2012, it was accepted for inclusion into the POSIX standard. See the Austin Group website.

Likewise, mawk manual says:

Nextfile is a gawk extension (also implemented by BWK awk), is not yet
part of the POSIX standard (as of October 2012), although it has been
accepted for the next revision of the standard.

What confuses me is that there is no mention of nextfile in the latest POSIX specification, from 2018.

Following the link to the Austin Group, you find that the issue was resolved in 2012 (with even a final accepted text), but only applied in 2020(!).

All in all, does it mean nextfile is an awk's feature specified by POSIX? Or will it only be so in a future POSIX version?

(For practical purposes, nextfile is also to be found in BSD awk.)

Two more statements are in the same situation as nextfile: fflush and delete (delete is already specified, but is to be expanded so as to be able to delete an entire array).

Best Answer

You'll see that bug 607 is targetted for Issue 8, not released yet (see the issue8 Tags).

Issue 7 was released in 2008, there have been a few newer editions of issue 7, latest in 2018, but those are technical corrigenda, they don't bring new features.

nextfile is not only a new feature but also breaks backward compatibility as awk '{nextfile = 1}' and awk '{nextfile}' are valid awk invocations which in the current POSIX version set and retrieve the value of a nextfile variable respectively, so it could possibly not be added as part of a technical corrigendum.

What could be added (and probably should have) in a TC is to tell people that nextfile is a word reserved for future use so that people should not use it in their variable or function names, as a script that does awk '{nextfile = 1}', though perfectly standard, does not work in many awk implementations (that's not limited to nextfile btw).

You can check a HTML rendition of the awk part of the 2018 edition of Issue 7 of the Single UNIX Specification at https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/awk.html (note the .2018edition part), though note that even though it is published by the Opengroup, the HTML version has no value of standard, only the PDF does (you need to register with them to get access to it).

They're meant to be equivalent, though there have been several bugs in the conversion to HTML in the past which have caused sections to be missing (though they're generally fixed quickly when spotted), so when in doubt, best is to check the PDF.