File: trivsed

package info (click to toggle)
clig 1.9.10-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 540 kB
  • ctags: 114
  • sloc: tcl: 1,908; ansic: 497; sh: 232; makefile: 117
file content (43 lines) | stat: -rwxr-xr-x 1,011 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/tclsh8.3
########################################################################
#
# I really don't know why I am doing this. It is only to support
# brain-dead platforms which don't know basic things like sed
#
########################################################################

lappend auto_path .
package require clig
namespace import ::clig::\[A-Za-z\]*

setSpec ::main
String -i infile {input file} -m
String -o outfile {output file} -m
Rest reps {pattern-replacement pairs} -c 2 oo
# proc catch {script args} {
#   uplevel 1 $script
#   set [lindex $args 0] bla
# }

set Program [file tail $argv0]

if {[catch {parseCmdline main $Program $argc $argv} err]} {
  puts stderr $err
  exit 1
}
if {[llength $reps]%2!=0} {
  puts stderr "$Program: there must be an odd number of arguments"
  exit 1
}

set in [open $infile r]
set out [open $outfile w]

while {-1!=[gets $in line]} {
  foreach {pat rep} $reps {
    regsub -all $pat $line $rep line
  }
  puts $out $line
}
close $in
close $out