【发布时间】:2021-06-30 13:55:45
【问题描述】:
我是这个论坛的新手,刚开始使用 awk,我喜欢做以下事情。
输入文件(input.log):
first word of file
second line in file
third and last line
awk 脚本 (test.awk) 到目前为止,我找到了字符串并将它们存储在一行的末尾打印:
/first/ ( aaa = $2 )
/in/ ( bbb = $1 )
/last/ ( ccc = $3 )
{ print aaa " , " bbb " , " ccc }
awk -f test.awk input.log
实际输出:
first word of file
first word of file
first word of file
word , first , of
second line in file
second line in file
second line in file
line , second , in
third and last line
third and last line
third and last line
and , third , last
预期(想要的)输出:
word , second , last
任何帮助和建议将不胜感激。
兄弟。伯特
【问题讨论】:
-
您的脚本似乎使用圆括号
()需要大括号。你说你想在最后打印结果,但是你没有END块。
标签: awk