"Randal L. Schwartz" wrote:
>
> >>>>> "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;
> }
Fair enough, though for truly oneoff stuff find |while read is still my
friend...
find ./ -type f -name *.bak -mtime +30 |while read f; do echo "removing
[$f]"; rm -f $f; done
(on solaris)
ps -ef|while read owner pid ppid other; do if test $owner == "real";
then echo "$owner: [$pid]"; fi; done
(you _are_ using a bourne derivative I hope :)
Cheers,
- Matt