#!/usr/local/bin/perl # # The purpose of this script is to scan a text file for an exact # phrase and substitute another for it. # # This is handy for changing web pages. # # # first, we'll assume that the command line arguments # are the names of the files that we want to change # *.html is usually good # @files_to_crunch = @ARGV ; $number_of_files_to_crunch = @files_to_crunch ; if ( $files_to_crunch[0] eq "" ) { print("Usage: sub.pl \n") ; print("the string you're looking for should go in the first line of ./phrase \n") ; print("the string you want to substitute should be the second line of ./phrase \n") ; exit ; } print("\n\nopening ./phrase looking for data\n\n") ; open(PHRASE,"./phrase") ; $old_phrase = ; $new_phrase = ; chop($old_phrase) ; chop($new_phrase) ; print("Looking for: $old_phrase\n\n") ; print("Substituting: $new_phrase\n\n") ; for( $i=0 ; $i<$number_of_files_to_crunch ; $i++ ) { print("Processing:$files_to_crunch[$i]\n") ; open(FILE,$files_to_crunch[$i]) ; open(NEWFILE,">$files_to_crunch[$i].sub") ; while( $line = ) { if ( $line =~ /\Q$old_phrase/ ) { $line =~ s/\Q$old_phrase/$new_phrase/ ; } print NEWFILE ($line) ; } system("/bin/mv -i $files_to_crunch[$i].sub $files_to_crunch[$i]") ; }