>>>>> "Jeff" == Jeff Yoak <[EMAIL PROTECTED]> writes:
Jeff> At 11:50 PM 6/7/01 +0000, scott lutz wrote:
>> I have a this fancy bit of recursive search and replace code that I
>> picked up somewhere, but I would greatly appreciate it if one of the
>> gurus could explain it in English for me:
>>
>> find . -type f -print0 | xargs -0 perl -pi -e 's/<<your original text
here> /<<your new text here>>/g'
Jeff> John already did a fine job of explaining this, but I wanted to add
Jeff> that it is a great expression that I find myself using almost daily.
Jeff> You might look at the man pages for find and xargs to learn more about
Jeff> what is happening. You'll find a lot of cool things like other values
Jeff> for -type (like 'd' for directory), other switches (like
Jeff> -name... modify the above to catch files ending in .html with -name
Jeff> "*.html") and -exec and more.
It's also good to learn to do this same thing in native Perl:
use File::Find;
@ARGV = ();
find sub {
## in here, $_ is the filename, and $File::Find::name is the full name
push @ARGV, $File::Find::name if -f;
}, ".";
## we've now loaded @ARGV with all filenames in current directory
## and subdirectories
$^I = ".bak"; # turn on -i.bak
## and now do replacements:
while (<>) {
s/<<original>>/<<new>>/g;
print;
}
It's almost short enough that I just type these in as a one-off
program.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!