我想从tcl脚本执行awk命令 [英] I want to execute awk command from tcl script
问题描述
我想从我的tcl脚本中执行以下命令
I want to execute the following command from my tcl script
exec /bin/awk '/Start/{f=1;++file}/END/{f=0}f{print > "/home/user/report/"file }' input
我收到此错误
awk: ^ invalid char ''' in expression
是否可以从tcl中执行这样的命令
is it possible to execute such command from tcl
谢谢
推荐答案
tcl手册页中的报价:
Quote from tcl man page:
从Unix shell调用转换命令时,应注意 接管单引号字符没有特殊的事实 对Tcl的意义.因此:
When translating a command from a Unix shell invocation, care should be taken over the fact that single quote characters have no special significance to Tcl. Thus:
awk '{sum += $1} END {print sum}' numbers.list
将被翻译为:
exec awk {{sum += $1} END {print sum}} numbers.list
因此,我会尝试不使用引号(因为不能正确地放入评论中,所以被发布为答案,这只是从Google的快速搜索中找到的答案)
So I would try without quotes (posted as answer as it can't fit properly in a comment, it's just a though from a quick search on google)
根据评论,您可以在var中创建awk脚本,例如:
as per comment you may create the awk script in a var before like:
set awk_command "/Start/{f=1;++file}/END/{f=0}f{print > \"$tcl_variable\"file }"
exec /bin/awk $awk_command input
这篇关于我想从tcl脚本执行awk命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!