【发布时间】:2021-11-11 09:28:43
【问题描述】:
#!/usr/bin/tcsh
cmd='BEGIN{c=0}{
if($1=="Net"){print $0}
if($1=="v14")
{
if($4>=200)
{print "Drop more than 200 at "$1}
}
}'
awk -f "$cmd" input_file.txt > output_file.txt
我正在尝试执行其中包含多行 awk 脚本的 shell 脚本。 将 awk 脚本(尤其是多行 awk 脚本)存储到变量 cmd 中,然后在 awk -f "$cmd" input_file.txt > output_file.txt 中执行该 cmd。
这给出了如下错误
awk: fatal: can't open source file `BEGIN{c=0}{
if($1=="Net"){print $0}
if($1=="v14")
{
if($4>=200)
{print"Drop more than 200 at $1}
}
}' for reading (No such file or directory)
我的任务是如何执行其中包含多行 awk 脚本的 shell 脚本? 你能帮我解决这个问题吗?即使在谷歌/参考手册中搜索后我也无法弄清楚?
【问题讨论】: