使用tcl执行sed命令时出错

时间:2015-12-22 09:37:09

标签: sed tcl

我使用的文件包含以下行:

first0.{j}.second1.{j}.third1 
first0.{j}.second2.{j}.third1

我想替换“.n。” “{j}”// n属于[1-100]

所以所需的行如下所示:

exec sed -i 's/\.[1-9]\./\.{j}\./g' file

我在tcl

下使用以下命令
invalid command name "1-9"

但我得到了

if ( has no success after 2-3 seconds ) {   
   re-fire HTTP call...
}

我该如何替换?

2 个答案:

答案 0 :(得分:5)

支持你的表达......

单引号不引用Tcl的机制,因此将awk表达式括起来,

exec sed -i {s/\.[1-9]\./\.{j}\./g} file

参考: Frequently Made Mistakes in Tcl

答案 1 :(得分:1)

如果你想在普通Tcl中这样做:

set filename "file"

set fh [open $filename r]
set data [read -nonewline $fh]
close $fh

set fh [open $filename w]
puts $fh [regsub -all {\.\d\.} $data {.{j}.}]
close $fh

exec cat $filename
first0.{j}.second1.{j}.third1 
first0.{j}.second2.{j}.third1 
相关问题