我正在从shell脚本
调用let f4 (processOptions:ProcessOptions) =
processOptions.func1.Invoke 4 |> ignore
processOptions.func2.Invoke "abc" |> ignore
f4 { func1 = f1; func2 = f1 }
,如下所示
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.
的价值?
答案 0 :(得分:1)
根据手册页,您应该在-f
之前传递选项:
SYNOPSIS
`gawk [ POSIX or GNU style options ] -f program-file [ -- ] file ...` `gawk [ POSIX or GNU style options ] [ -- ] program-text file ...`
答案 1 :(得分:1)
您需要更改行
/<keyword>inputKeyword<\/keyword>/ { found=1 }
到
$0 ~ "<keyword>"inputKeyword"</keyword>" { found=1 }
如果匹配模式(//
)在变量中,则不需要regex
。 awk
无法插入//
之间的内容。它将被视为一个字符串。