I’m reading The UNIX Programming Environment and in Section 4.4, about awk, there is this sample code:
awk '
FILENAME != prevfile { # new file
NR = 1 # reset line number
prevfile = FILENAME
}
NF > 0 {
if ($1 == lastword)
printf "double %s, file %s, line %d\n",$1,FILENAME,NR
for (i = 2; i <= NF; i++)
if ($i == $(i-1))
printf "double %s, file %s, line %d\n",$i,FILENAME,NR
if (NF > 0)
lastword = $NF
}' $*
Why is NF > 0 tested inside the block which already had a NF > 0 as a pattern?
Contained within the errata notes for this book:
So it was a mistake made by the publisher and/or copy editor.