OLD | NEW |
1 #!/usr/bin/tcl | 1 #!/usr/bin/tcl |
2 # | 2 # |
3 # Replace string with another string -OR- include | 3 # Replace string with another string -OR- include |
4 # only lines successfully modified with a regular | 4 # only lines successfully modified with a regular |
5 # expression. | 5 # expression. |
6 # | 6 # |
7 set mode [string tolower [lindex $argv 0]] | 7 set mode [string tolower [lindex $argv 0]] |
8 set from [lindex $argv 1] | 8 set from [lindex $argv 1] |
9 set to [lindex $argv 2] | 9 set to [lindex $argv 2] |
10 if {$mode ni [list exact include]} {exit 1} | 10 if {$mode ni [list exact include]} {exit 1} |
11 if {[string length $from]==0} {exit 2} | 11 if {[string length $from]==0} {exit 2} |
12 while {![eof stdin]} { | 12 while {![eof stdin]} { |
13 set line [gets stdin] | 13 set line [gets stdin] |
14 if {[eof stdin]} break | 14 if {[eof stdin]} break |
15 switch -exact $mode { | 15 switch -exact $mode { |
16 exact {set line [string map [list $from $to] $line]} | 16 exact {set line [string map [list $from $to] $line]} |
17 include {if {[regsub -all -- $from $line $to line]==0} continue} | 17 include {if {[regsub -all -- $from $line $to line]==0} continue} |
18 } | 18 } |
19 puts stdout $line | 19 puts stdout $line |
20 } | 20 } |
OLD | NEW |