#!/usr/local/bin/perl if ($#ARGV < 2) { print<<"end_tag"; # $0 opens a file for reading and changes a name in the file # use: $0 OLD_NAME NEW_NAME FILE_LIST # param 1 is the old value # param 2 is the new value # param +2 is file list. There is no programatic limit to the number of files processed # the original file will be copied into a .bak file # the original file will be overwritten with the substitution # the script assumes the file(s) to be modified are in the directory that the # script was started from # SYMBOLIC LINKS are NOT followed end_tag exit(1); } $OLD = shift; # dump arg(0) $NEW = shift; # dump arg(1) # now argv has just the file list in it. select(OUTFILE); while (<>) { next if -l $ARGV; #skip this file if it is a sym link $count++ ; print STDOUT "." if (($count % 10) == 0); if ($ARGV ne $oldargv) #have we saved this file ? { close(OUTFILE); print STDOUT "\nprocessing $ARGV ..."; $count = 0 ; rename($ARGV, $ARGV . '.bak'); #mv the file to a backup copy $oldargv = $ARGV ; open (OUTFILE, ">$ARGV");# open the file for writting } s/$OLD/$NEW/go;# perform substitution # o - only interpret the variables once print; #dump the file back into itself with changes } close(OUTFILE); select(STDOUT); print "\n";