Well, this could range on up there with an extremely simple task (in perl or shell) to very difficult depending on just how complex your pages are. At any rate, before doing anything you should make a copy of all the files and tar/gzip them up somewhere in case something goes wrong. So, without further adieu and assuming you did tar/gzip I will start with shell since that is simplest for me at this time in my perl knowledge (or lack thereof...but I will try to put a perl one down too...which it is just a one-liner). Also note, that I am assuming the simplest form of your situation meaning that there are nothing odd about your href tags and that they are pretty standard. I am also assuming (lots of assumptions going on eh? :) that you will be working in the same directory with no sub-directories where these files reside and that they are all there. I am assuming they are all called *.html or *.asp.
user@yourbox /home/httpd/html ] $ ls *.html *.asp | while read file;do
+ newfile="$file.fixed";sed s/\.html/\.asp/ $file > $newfile;done
This lil one liner will change EVERYTHING that is .html to .asp in every $file and create a new file called $file.fixed. theoretically, this means you will have not lost the originals and you can check the originals against the new files. This transformation might be undesirable but since I don't know the specifics it is the best I can do at this point with a shell one liner.
Now for Perl. (I am fully up to any assistance as I am still learning Perl)
#!/usr/local/bin/perl -w
use strict;
use cwd;
# open our current directory
opendir(DD,".") or die("Cannot open ". getcwd ."\n");
# read our files getting only files named *.html
# and *.asp
my @FILES = grep(/(\.html|\.asp),readdir(FD)) or die ("Could not get d
+irectory listing: $!\n");
# close our directory descriptor
close(DD);
# walk our array that has the file names in it we should go through.
while ( @FILES ) {
my $file = $_ ;
my $newfile = "$file.fixed";
# open two descriptors
# FD for our original files
open(FD,$file) or die("Cannot open $file\n";
# NEW for our newly created (hopefully fixed) files.
open(NEW,">>$newfile") or die ("Cannot open $newfile for writing\n
+");
# walk each file
while ( <FD> ) {
chomp;
# replace anything in a line with <a href in it
# that has .html to .asp
if ( grep(/<a href/) ) {
my $newline =~ s/\.html/\.asp/;
# append that to the new file.
print NEW "$newline\n";
} else {
# otherwise just append the old line into
# the file.
print NEW "$_\n";
}
}
# Close the descriptor for these files before
# the next loop iteration
close(NEW);
close(FD);
}
This is untested code as I just wrote it here in this window. So go through it first. I think the perl one would be way more thorough than the shell line. Anyway, I was rushed too. I gotta get back to work. If something is wrong I apologize. Good luck.
----------
- Jim |