在我的unix shell脚本中
filename=myfile
LOG=/dir/log*
j=`awk '/AAAA/ && /BBB/ && /${filename}/ && /CCC/' ${LOG}`
Run Code Online (Sandbox Code Playgroud)
但是当脚本运行时,使用set -x我看到:
awk /AAA/ && /BBB/ && /${filename}/ && /CCC/ /dir/log1 /dir/log2
Run Code Online (Sandbox Code Playgroud)
如何在awk参数中转义$ {filename}变量以使其正确解析?
说明我想做什么
我有一个名为/tmp/S20150814.001的文件,其中包含
This line contains AAAA and BBB and CCC and bcd_input_13082015_0800.txt
Run Code Online (Sandbox Code Playgroud)
在我的脚本中,如果我使用
MYLOG=/tmp/S20150814.001
j=`awk '/AAAA/ && /BBB/ && /bcd_input_13082015_0800.txt/ && /CCC/' ${MYLOG}`
if [[ ${#j} -gt 0 ]]
then
Run Code Online (Sandbox Code Playgroud)
并运行我看到的脚本
+ + awk /AAAA/ && /BBB/ && /bcd_input_13082015_0800.txt/ && /CCC/ /tmp/S20150814.001
j=This line contains AAAA and BBB and CCC and bcd_input_13082015_0800.txt
+ …Run Code Online (Sandbox Code Playgroud)