【发布时间】:2016-02-12 17:26:07
【问题描述】:
我正在从 shell 脚本调用myAwk.awk,如下所示,
awk -f myAwk.awk -v inputKeyword="SEARCH" 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 的值在我需要的地方可用?
【问题讨论】:
-
不能和
/.../一起使用,用~来匹配。