in reply to Re: Search & Replace in subdirectory files
in thread Search & Replace in subdirectory files

Not really sure how to make it recurse subdirectories other than adding /* on the end for each level needed:
 # perl -p -i.bak -e 's/bilbo/frodo/g' */*
Then we are back at File::Find.
#!/usr/bin/perl use File::Find; my @dirs = @ARGV; @ARGV = (); File::Find::find( { wanted => sub { push @ARGV, $File::Find::name if -f } }, @dirs ); $^I = '.bak'; local $_; while ( defined( $_ = <ARGV> ) ) { s/bilbo/frodo/g; print; }
Boris

Replies are listed 'Best First'.
Re: Re: Re: Search & Replace in subdirectory files
by bassplayer (Monsignor) on Apr 23, 2004 at 16:05 UTC
    Not necessarily. File::Find is the solution I would use if the script is to be run regularly. However, with a one time change, I would still use the command line. It's just so easy. If I have five levels to recurse, I run it five times. Granted, if there is an unknown level of subdiectories, then a folder could be missed, but this one-liner has served me well and I just thought I'd share it. TIMTOWTDI, right? I guess I should have explained that in previous reply.

    bassplayer