View Single Post
Old 09-16-2006, 02:34 PM  
boldy
Macdaddy coder
 
Industry Role:
Join Date: Feb 2002
Location: MacDaddy pimp coder
Posts: 2,806
I'm in a good mood today so i wrote this little perl script for you :
uploaded it and call it test.pl

then run it from the command shell:
(make sure you're into the public_html dir)


perl test.pl


Code:
#!/usr/bin/perl
# by boldy / EarlmillerCash.com
# Now promote Earlmillercash.com goddamnnit :) 

my $lSearch = "foobar";
my $lReplace = "whatever";

# this will search and replace the above words, and it will create
# filename.html.test files if it matches the action.
# if you think it workds set $lTest to "" instead of ".test"
#
# and it will overwrite the file.
# make sure you're in the right directory by cd ing itto it
# eg .
# cd /web/sites/yourdomain.com/public_html

# set $lTest to "" when you think this works
# to delete the *.test files run: find ./ -name *\.test -exec rm {} \;

my $lTest = ".test";
my @lFiles = split ("\n" , `find ./ -type f` );

foreach my $lFile (@lFiles) {
   print "Opening file " . $lFile . "\n";
   open (INFILE,"<" . $lFile);
   my @lLines =<INFILE>;
   close INFILE;

   my $lWrite = 0;
   foreach my $lLine (@lLines) {
      if ($lLine =~ m/$lSearch/) {
            $lWrite = 1; last;
      }
   }
   if ($lWrite) {
      open (OUTFILE , ">" . $lFile . $lTest );
      foreach my $lLine (@lLines) {
         $lLine =~ s/$lSearch/$lReplace/g;
         print OUTFILE $lLine;
      }
      close OUTFILE;
      print $lFile.$lTest  . " created \n";
   }
}
__________________
MacDaddy Coder.
boldy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote