【发布时间】:2019-02-09 01:43:14
【问题描述】:
在 awk 处理输入文件之前,我需要知道需要多少条记录。
为了确定这一点,我在 awk 脚本的 BEGIN 段中有以下代码....
BEGIN {
p = ""
j = 1
getline # Activates the FILENAmE variable which normally is not available in the BEGIN section of an awk script.
n = system("wc -l " FILENAME) # Assign the result (i.e. number of records in FILENAME) to the n variable.
gsub(FILENAME, "|", n) # Remove the input file name appended to the result and replace with "|" just to see what it's done!
print n # See what the hell has happened.
}
我希望看到 n 显示记录数,但我的输出看起来像这样......
12 accounts12
0
“accounts12”是我的输入文件的名称....
【问题讨论】:
-
您的输入始终是文件还是来自管道的流?