Reputation: 3452
The file that I use contains lines like following:
first0.1.second1.1.third1
first0.1.second2.2.third1
first0.n.second2.n.third1
I want to replace ".n." with "{j}" // n belong to [1-100]
So the desired lines are like the following:
first0.{j}.second1.{j}.third1
first0.{j}.second2.{j}.third1
I use the following command under tcl
exec sed -i 's/\.[1-9]\./\.{j}\./g' file
but I got
invalid command name "1-9"
How can I do this substitution?
Upvotes: 0
Views: 123
Reputation: 246992
If you want to do that in plain 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
Upvotes: 1
Reputation: 16428
Brace your expressions...
Single quotes are not quoting mechanism for Tcl
, so brace your awk
expressions as,
exec sed -i {s/\.[1-9]\./\.{j}\./g} file
Reference : Frequently Made Mistakes in Tcl
Upvotes: 5