2015-10-10 03:55:57 +02:00
|
|
|
#!/usr/bin/tcl
|
|
|
|
#
|
|
|
|
# Replace string with another string -OR- include
|
|
|
|
# only lines successfully modified with a regular
|
|
|
|
# expression.
|
|
|
|
#
|
2024-07-30 17:49:02 +02:00
|
|
|
fconfigure stdout -translation binary
|
|
|
|
fconfigure stderr -translation binary
|
2015-10-10 03:55:57 +02:00
|
|
|
set mode [string tolower [lindex $argv 0]]
|
|
|
|
set from [lindex $argv 1]
|
|
|
|
set to [lindex $argv 2]
|
2021-09-11 00:00:43 +02:00
|
|
|
if {-1 == [lsearch -exact [list exact regsub include] $mode]} {exit 1}
|
2015-10-10 03:55:57 +02:00
|
|
|
if {[string length $from]==0} {exit 2}
|
|
|
|
while {![eof stdin]} {
|
|
|
|
set line [gets stdin]
|
|
|
|
if {[eof stdin]} break
|
|
|
|
switch -exact $mode {
|
|
|
|
exact {set line [string map [list $from $to] $line]}
|
2016-07-28 16:37:04 +02:00
|
|
|
regsub {regsub -all -- $from $line $to line}
|
2015-10-10 03:55:57 +02:00
|
|
|
include {if {[regsub -all -- $from $line $to line]==0} continue}
|
|
|
|
}
|
|
|
|
puts stdout $line
|
|
|
|
}
|