Subscribefind . -name "*.html" | while read i; do cp "$i" "$i.bak"; prefix=`basename "$i" | cut -c 1-3`; sed -e "s/VARIABLE/$prefix/g" "$i" > tmpfile; mv tmpfile "$i"; donefor i in *.html; do echo "<a href=\"zzzzz?${i:0:3}\">blabla</a>" >> "$i"
use strict;
use File::Copy "cp";
while (<*.html>) {
my $filename = $_;
my $first_three_letters = substr( $filename, 0, 3 );
cp( "$filename", "$filename.bak" );
print "copied $filename to $filename.bak for backup\n";
open( INPUT, '<', $filename ) or die "couldn't open $filename: $!\n";
my $content = join( '', <INPUT> );
close(INPUT);
if ( $content =~
s|</body>|<a href="x?$first_three_letters">link</a></body>|i )
{
print "added link to x?$first_three_letters before the close body tag";
open( OUTPUT, '>', $filename )
or die "Couldn't open $filename for writing: $!";
print OUTPUT $content;
close(OUTPUT);
}
else {
print "couldn't do the replacement for some reason!\n";
print "$filename unchanged\n";
}
}
You are not logged in, either login or create an account to post comments
posted by mullingitover at 8:14 PM on April 8