#!/usr/athena/bin/perl $pwd = `pwd`; chomp $pwd; print "Globrep will replace $ARGV[0] with \n", "$ARGV[1] throughout the entire tree of \n", "$pwd. Is this correct? "; $resp = ; die if $resp !~ /^[Yy]/; $output = "/var/tmp/dirlist.txt"; `ls -R $pwd > $output`; open TREE, $output; while () { if ($_ =~ /:$/) { chomp $_; chop $_; $_ .= "\n"; push @dirlist, $_; } } close TREE; unlink $output; $search_string = $ARGV[0]; $replace_string = $ARGV[1]; foreach $dir (@dirlist) { chomp $dir; @filelist = `ls -l $dir | grep "^\-" | cut -c55-100`; foreach $filename (@filelist) { $fullname = $dir . "/" . $filename; if ($fullname =~ /_$/) { unlink $fullname; } else { open ORIG, $fullname || die "Could not read $fullname: $!\n"; chomp $fullname; $backup = $fullname . ".bak"; open BACKUP, ">$backup" || die "Cannot create backup file: $!\n"; while () { print BACKUP $_; } close BACKUP; close ORIG; unlink $fullname; open BACKUP, $backup; open NEW, ">$fullname"; while () { s/$search_string/$replace_string/gi; print NEW; } close NEW; close BACKUP; unlink $backup; } } }