Using a Variable in a sed command called in Tcl Script

不打扰是莪最后的温柔 提交于 2019-12-25 01:43:20

问题


I want to use the following command in a tcl script :

sed -n '452,$ { /wire/ {p;q} }' /tmp/foo

For that I have changed this command as follow :

set MIDLINE2 [ exec sed -n {1134,$ {/wire/{=;q}}} foo.txt ] 

It gives me correct answer but in place 1134 I want to use variable $MIDLINE that has value 1134. How can I do that ? Please suggest some way.


回答1:


This is a simple problem of quoting. You're using curly braces which inhibits variable substitution. Since you want variable substitution you need to use something else.

set MIDLINE2 [ exec sed -n "$MIDLINE,\$ {/wire/{=;q}}" foo.txt ]

Notice that you have to put a backslash in front of the literal $, otherwise Tcl will try to substitute that, too.



来源:https://stackoverflow.com/questions/11563137/using-a-variable-in-a-sed-command-called-in-tcl-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!