$ sed s/foo/bar/ < infile > outfilecan in Tcl be substituted either with regsub or, when like in this case, no regular expression features are needed, with string map:
% > outfile [regsub -all foo [< infile] bar]resp.
% > outfile [string map {foo bar} [< infile]]where proc > {filename str} {set f [open $filename w]; puts $f $str; close $f}
proc < {filename} {set f [open $filename]; return [read $f][close $f]}RS 2006-09-05: Playing around, waiting for a longish run to complete:
proc sed {script input} {
set sep [string index $script 1]
foreach {cmd from to flag} [split $script $sep] break
if {$cmd ne "s"} {error "not yet implemented"}
set cmd regsub
if {$flag eq "g"} {lappend cmd -all}
lappend cmd $from $input $to
eval $cmd
}Testing:sed s-foo-bar "A foolish idea for fools" A barlish idea for fools % sed s/foo/bar/g "A foolish idea for fools" A barlish idea for barlsAdd to it to make it come closer to the real thing:^)
[ Category Acronym | Category Application ]
