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)
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.#!/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); }
----------
- Jim
In reply to Re: Changing .html to .asp
by snafu
in thread Changing .html to .asp
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |