[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: recusive ls/search/replace function!!



On Tuesday, Apr 26th 2005 at 15:17 -0700, quoth bruce:

=>hi..
=>
=>can't figure this out. it's basic.. how can i do a find of all files in
=>underlying recursive dirs. also, how can i do a search/replace of txt in all
=>files that match a certain extension..

find . -type f 

Here's a handy lil thing. replace_str

#!/usr/bin/perl -i.old

$from_text = shift ;
$to_text = shift ;

eval "while( <> ) {

        s/$from_text/$to_text/go ;
        print ;
}" ;


find . -type f -name \*.certain | xargs replace_str old new

=>
=>ie, how do i find all files that end in 'int' in the underlying dirs...
=>or, how do i replace "foo' with 'dog' in all underlying dirs that end in
=>'ddf'..

find . -type f -name \*.int

find $(find . -type d -name \*.ddf) -type f | xargs replace_str foo dog

=>
=>i can see that 'ls -R * can/should get me all underlying files... but...
=>
=>i can also see that find . -name "*.int" would work to find the files... but
=>i'm not sure how to get the rest.
=>
=>-bruce
=>bedouglas earthlink net

Please learn to use xargs and not to use -exec in the find command. The 
-exec option will generate a seperate process for every filename match. 
The xargs command will collect as many arguments as it can to minimize the 
number of forks that occur.

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]