问题
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