在 Tcl 脚本中调用的 sed 命令中使用变量 [英] Using a Variable in a sed command called in Tcl Script

查看:85
本文介绍了在 Tcl 脚本中调用的 sed 命令中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 tcl 脚本中使用以下命令:

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 ] 

它给了我正确的答案,但在 1134 的位置我想使用值为 1134 的变量 $MIDLINE.我该怎么做?请提出一些建议.

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.

推荐答案

这是一个简单的引用问题.您正在使用禁止变量替换的花括号.由于您想要变量替换,因此您需要使用其他东西.

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 ]

请注意,您必须在文字 $ 前面放一个反斜杠,否则 Tcl 也会尝试替换它.

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

这篇关于在 Tcl 脚本中调用的 sed 命令中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆