AWK:无法访问传递的参数 [英] awk : Not able to access the passed parameter
本文介绍了AWK:无法访问传递的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我调用 myAwk.awk
类似下面的shell脚本,
I am invoking myAwk.awk
like below from shell script,
的awk -f myAwk.awk -v inputKeyword =搜索file2.xml
$bash: cat myAwk.awk
BEGIN{
print "This is from awk script:" inputKeyword; //This prints SEARCH string. Fine.
}
/<record / { i=1 }
i { a[i++]=$0 }
/<\/record>/ {
if (found) {
for (i=1; i<=length(a); ++i) print a[i] >> resultFile.xml
}
i=0;
found=0
}
/<keyword>inputKeyword<\/keyword>/ { found=1 } //Looks like the value for inputKeyword is not available here.
//There are no errors though.
我怎样才能让 inputKeyword
的值,可在我需要的地方?
How can I make the value of inputKeyword
to be available at my required place?
推荐答案
您需要更改行
/<keyword>inputKeyword<\/keyword>/ { found=1 }
到
$0 ~ "<keyword>"inputKeyword"</keyword>" { found=1 }
不要求你 //
,如果匹配模式(正则表达式
)是可变的。 AWK
不插之间有什么//
。这将被视为只是一个字符串在那里。
You do not required //
, if matching pattern(regex
) is in variable. awk
won't interpolate what's between //
. It will be considered just a string in there.
这篇关于AWK:无法访问传递的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文