awk - NF > 0 checked two times on The UNiX Programming Environment -


i'm reading unix programming environment , in section 4.4, awk, there 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 (i = 2; <= nf; i++) if ($i == $(i-1)) printf "double %s, file %s, line %d\n",$i,filename,nr if (nf > 0) lastword = $nf }' $* 

why nf > 0 tested inside block had nf > 0 pattern?

contained within errata notes book:

page 121, first program: test "if (nf > 0)" unnecessary. 

so mistake made publisher and/or copy editor.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -