how to use sed from a tcl file how to use sed from a tcl file unix unix

how to use sed from a tcl file


What am I doing wrong?

What you're doing wrong is using ' (single quote) characters. They're not special to Tcl at all. The equivalent in Tcl is enclosing a word in {braces}; it gives no special treatment at all to the characters inside. Thus, what you seek to do would be:

exec /bin/sed {s/ +/ /g} $file

Mind you, if you're doing something more complex and the restriction of Tcl to whole-words being unquoted, then you might instead go for this:

exec /bin/sh -c "sed 's/ +/ /g' $file"

Or, real idiomatic Tcl just doesn't use sed for something this simple:

set f [open $file]set replacedContents [regsub -all { +} [read $f] " "]close $f


Use exec /bin/sed "s/\ +/\ /g" $file

The '\ ' tells TCL that there's an space there. Also using the '"' configures properly the string.