在 tcl 文件中使用 sed
using sed in a tcl file
您好,我是 tcl 新手,遇到过如下问题。
在这段代码中,我试图只从文件中获取第 1 行和第 2 行,并想将它们放入另一个变量中。但是这段代码对我不起作用。
set sed_com "${line1},${line2}p"; # the value of this sed command is 1,2p
set tmp [exec sh -c {sed -n "${sed_com}" file.tmp | tail -n 1}]; # this one won't work
set tmp [exec sh -c {sed -n "1,2p" file.tmp | tail -n 1}]; # this one will work
我想知道是否有办法让 tcl 文件像第 3 行一样解释它?
为什么要加入 sh -c
让事情变得复杂?你可以这样做:
set tmp [exec sed -n $sed_com file.tmp | tail -n 1]
您好,我是 tcl 新手,遇到过如下问题。
在这段代码中,我试图只从文件中获取第 1 行和第 2 行,并想将它们放入另一个变量中。但是这段代码对我不起作用。
set sed_com "${line1},${line2}p"; # the value of this sed command is 1,2p
set tmp [exec sh -c {sed -n "${sed_com}" file.tmp | tail -n 1}]; # this one won't work
set tmp [exec sh -c {sed -n "1,2p" file.tmp | tail -n 1}]; # this one will work
我想知道是否有办法让 tcl 文件像第 3 行一样解释它?
为什么要加入 sh -c
让事情变得复杂?你可以这样做:
set tmp [exec sed -n $sed_com file.tmp | tail -n 1]