What am I doing wrong?
What are you wrong with, use the characters ' (single quotes). They are not at all special to Tcl. Equivalent in Tcl encloses a word in { brackets } ; he does not give any special treatment to the characters inside. So you want to do the following:
exec /bin/sed {s/ +/ /g} $file
Keep in mind if you are doing something more complex and restricting Tcl to whole words that are not ordered, then you can go for this instead:
exec /bin/sh -c "sed 's/ +/ /g' $file"
Or, the real idiomatic Tcl just doesn't use sed for something so simple:
set f [open $file] set replacedContents [regsub -all { +} [read $f] " "] close $f
Donal fellows
source share