如何在 awk 命令中使用变量作为输入?
How can I use a variable as input in a awk command?
我有这个变量:
a='/08/OPT/imaginary/N/08_i_N.out'
我想使用“/”作为字段分隔符。
然后,我要提取第一个模式。
我试过:
awk -F/ '{print }' "$a"
但我得到:
awk: cannot open /08/OPT/imaginary/N/08_i_N.out (No such file or directory)
我不想要该文件,只在该文件的路径上工作。
与任何其他命令相同,这些(或其他替代方案,例如在“此处文档”中或作为 awk 变量传递或...):
printf '%s\n' "$a" | command
command <<<"$a"
我有这个变量:
a='/08/OPT/imaginary/N/08_i_N.out'
我想使用“/”作为字段分隔符。
然后,我要提取第一个模式。
我试过:
awk -F/ '{print }' "$a"
但我得到:
awk: cannot open /08/OPT/imaginary/N/08_i_N.out (No such file or directory)
我不想要该文件,只在该文件的路径上工作。
与任何其他命令相同,这些(或其他替代方案,例如在“此处文档”中或作为 awk 变量传递或...):
printf '%s\n' "$a" | command
command <<<"$a"