Awk: Version && nextfile

How can I find which version of Awk is installed? OpSystem is HPUX 11.x

I am getting an error when trying to use the keyword nextfile and I dont know why! (Well, I can only assume that I have am using a version of Awk that does not support nextfile. However, according to O'Reilly, nextfile is apart of the Bell Labs version of Awk - which is the version I suspect that I am using)

Error is:
awk: A statement occurred that is not valid.
The input line number is 1. The file is /dir1/dir2/dir3/file.dat
The source line number is 36.

You are probably using a POSIX version of awk that came with your OS. nextfile is part of gawk:

7.4.8 Using gawk's 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.

Cheers,

Keith

Since I dont have nextfile available to me, how can I control which file is being processed by my awk program? I had thought the value of NR would be reset after each file but that doesnt seem to be the case.

The version of awk shipped with HP-UX is POSIX-complient
and I believe essentially a version of the AT&T Toolchest
nawk (new awk).

nawk does not support the nextfile keyword.

nextfile is a specific gawk extension.

See the GNU awk users guide (www.gnu.org) for details
of how to implement nextfile as an awk function. The code
is as follows but you should read the full text to understand
side effects, etc.

# nextfile --- skip remaining records in current file
# correctly handle successive occurrences of the same file
# this should be read in before the "main" awk program

function nextfile() { _abandon_ = FILENAME; next }

_abandon_ == FILENAME {
if (FNR == 1)
_abandon_ = ""
else
next
}

  • Finnbarr