简体   繁体   中英

using sed in a tcl file

Hi I am new tcl and have faced the issue like below.

In this code, I was trying to get only line 1 and 2 from a file and want to put them into another variable. But this code didn't work for me.

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

I was wondering if there is a way that we could make the tcl file interpret it like the line 3?

Why are you complicating things by throwing in the sh -c ? You can just do:

set tmp [exec sed -n $sed_com file.tmp | tail -n 1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM