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


In reply to Re: Changing .html to .asp by snafu
in thread Changing .html to .asp by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.