我正在阅读 The UNIX Programming Environment 和第 4.4 节,关于 awk,有这个示例代码:
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
}' $*
为什么在已经有 NF > 0 作为模式的块内测试 NF > 0?