AWK 的 END 块中是否定义了字段?
Are fields defined in the END block in AWK?
在 END
块中使用 </code>、<code>
会发生什么,例如:
awk '{print }END{print }'
我发现 </code> 和 <code>
保留了最后一条记录的值。这种行为是由标准保证的还是特定于实现的?
检查 docs 我们发现它是 实现特定的 :
Traditionally, due largely to implementation issues, [=10=] and NF were
undefined inside an END rule. The POSIX standard specifies that NF is
available in an END rule. It contains the number of fields from the
last input record. Most probably due to an oversight, the standard
does not say that [=10=] is also preserved, although logically one would
think that it should be. In fact, all of BWK awk, mawk, and gawk
preserve the value of [=10=] for use in END rules. Be aware, however, that
some other implementations and many older versions of Unix awk do not.
在 END
块中使用 </code>、<code>
会发生什么,例如:
awk '{print }END{print }'
我发现 </code> 和 <code>
保留了最后一条记录的值。这种行为是由标准保证的还是特定于实现的?
检查 docs 我们发现它是 实现特定的 :
Traditionally, due largely to implementation issues, [=10=] and NF were undefined inside an END rule. The POSIX standard specifies that NF is available in an END rule. It contains the number of fields from the last input record. Most probably due to an oversight, the standard does not say that [=10=] is also preserved, although logically one would think that it should be. In fact, all of BWK awk, mawk, and gawk preserve the value of [=10=] for use in END rules. Be aware, however, that some other implementations and many older versions of Unix awk do not.