SPUG: to change a file in different folders

Yitzchak Scott-Thoennes sthoenna at efn.org
Tue Jan 18 02:53:14 PST 2005


On Tue, Jan 18, 2005 at 02:06:24PM +0550, Sachin Chaturvedi wrote:
> i want to modify a file i a file, say output.txt whaich is present in different folders.
> for eg...
> 
> there is a line in output.txt 
> source ../setext.cmd 
> and i want to change it to  
> source $testfolder/../setext.cmd.
> 
> i can do from comand line as perl -pi -e 's/old/new/g' output.txt 
> 
> but since this is in different folders i want to change all the output.txt in one shot calling script which automatically changes 
> the folder one by one calls the above command and work is done

You can give more than one filename in place of output.txt, and they can
include the folder name, so you could do:

perl -pi -e 's/old/new/g' foo/output.txt bar/baz/output.txt

or:

perl -pi -e 's/old/new/g' */output.txt

or:

find . -name output.txt | xargs perl -pi -e's/old/new/g'


More information about the spug-list mailing list