我從shell腳本調用myAwk.awk
像下面,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
值可用在我需要的地方?
你不能在'/.../'中使用它,使用'〜'來匹配。 –