更新时间:2022-03-19 23:26:02
您可以将值保存在变量中,然后在处理整个文件后将其打印出来:
You can save the value in a variable and then print it after processing the whole file:
awk '/foo/ {a=$0} END{print a}' file
$ cat file
foo1
foo2
foo3
4
5
$ awk '/foo/ {a=$0} END{print a}' file
foo3