-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathinsafter
More file actions
45 lines (40 loc) · 874 Bytes
/
insafter
File metadata and controls
45 lines (40 loc) · 874 Bytes
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
44
45
#!/usr/local/bin/perl
# Insert some file after the first occurence of a given tag
#
# Arnaud Le Hors - lehors@w3.org
# $Id: insafter,v 1.3 2006-10-09 18:55:52 ihickson Exp $
$PROGNAME = substr($0, rindex($0, "/") + 1);
if ($#ARGV < 3) {
print "Usage: $PROGNAME src src2 tag trgt\n";
exit 1;
} else {
$input = $ARGV[0];
$input2 = $ARGV[1];
$tag = $ARGV[2];
$output = $ARGV[3];
}
### main
if (!open(INPUT, $input)) {
print STDERR "$PROGNAME Error: Cannot open file: $input\n";
exit 1;
}
if (!open(INPUT2, $input2)) {
print STDERR "$PROGNAME Error: Cannot open file: $input2\n";
exit 1;
}
open(OUTPUT, "> $output");
LOOP: while (<INPUT>) {
print OUTPUT $_;
if (/<$tag>/i) {
while (<INPUT2>) {
print OUTPUT $_;
}
last LOOP;
}
}
while (<INPUT>) {
print OUTPUT $_;
}
close(INPUT);
close(INPUT2);
close(OUTPUT);