为什么这个 AWK 脚本会导致语法错误?
基本上,我通过从表的列中获取值来创建 XML 文件。 我正在从 shell 脚本(ksh 如果重要的话)如下:
SQL_RESULT=`sqlplus -s ${CONNECT_STRING} << EOF
${SQLPLUS_SETTINGS}
select customer_id from GD9_GENTH_CUST_SUBSCR;
exit;
EOF`
FILE_LIST=`echo $SQL_RESULT|sed -e 's/\n/''/g'`
echo $FILE_LIST|awk -f awk.file
AWK 脚本 awl.file 包含:
BEGIN {
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?><GenTransactionHandler xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><EntityToPublish>\n<Entity type=\"C\" typeDesc=\"Customer level\"><TargetApplCode>UHUNLD</TargetApplCode><TrxName>GET_CUST_DATA</TrxName>"
}
{
print "<value>"$1"</value>"
}
END
{
print "</Entity>\n</EntityToPublish></GenTransactionHandler>"
}
当我运行脚本时,它给我一个 AWK 错误。
这有什么问题吗?
Basically, I am creating an XML file by taking the values from a column of a table.
I am starting an AWK script from a shell script (ksh if it matters) like this:
SQL_RESULT=`sqlplus -s ${CONNECT_STRING} << EOF
${SQLPLUS_SETTINGS}
select customer_id from GD9_GENTH_CUST_SUBSCR;
exit;
EOF`
FILE_LIST=`echo $SQL_RESULT|sed -e 's/\n/''/g'`
echo $FILE_LIST|awk -f awk.file
The AWK script, awl.file, contains:
BEGIN {
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?><GenTransactionHandler xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><EntityToPublish>\n<Entity type=\"C\" typeDesc=\"Customer level\"><TargetApplCode>UHUNLD</TargetApplCode><TrxName>GET_CUST_DATA</TrxName>"
}
{
print "<value>"$1"</value>"
}
END
{
print "</Entity>\n</EntityToPublish></GenTransactionHandler>"
}
When I run the script it gives me an AWK error.
What is the problem with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您收到与此类似的错误:
通过将左括号移至与 END 相同的行来修复代码:
If you are getting an error similar to this:
Fix your code by moving the open bracket to the same line as END:
这句话:
也可以很容易地是:
但没有人做任何事情。如果您的目的是用空字符串替换所有换行符,请执行以下操作:
或使用空格:
如果您实际上想用一对单引号替换所有换行符,那就有点复杂:
This line:
could just as easily be:
but neither one does anything. If your intention is to replace all the newlines with a null string then do this:
or with a space:
If you actually want to replace all the newlines with a pair of single quotes, that's a little more complicated:
由于您已经使用 awk,因此没有必要使用 sed 或其他工具(如 tr)将换行符替换为 nul。
@OP,问题可能出在你的引用中……但这只是一个猜测。显示您的 sql 输出以供进一步分析
since you are using awk already, it is not necessary to use sed or other tools like tr to replace newlines with nul.
@OP, problem may be in your quoting..but that's just a guess. show your sql output for further analysis