3 # Replace string with another string -OR- include
4 # only lines successfully modified with a regular
7 fconfigure stdout
-translation binary -encoding binary
8 fconfigure stderr
-translation binary -encoding binary
9 set mode
[string tolower
[lindex $argv 0]]
10 set from
[lindex $argv 1]
11 set to
[lindex $argv 2]
12 if {$mode ni
[list exact
regsub include
]} {exit 1}
13 if {[string length
$from]==0} {exit 2}
14 while {![eof stdin
]} {
16 if {[eof stdin
]} break
18 exact
{set line
[string map
[list $from $to] $line]}
19 regsub {regsub -all -- $from $line $to line
}
20 include
{if {[regsub -all -- $from $line $to line
]==0} continue}