Gossamer Forum
Home : General : Perl Programming :

mass replace in a directory...

Quote Reply
mass replace in a directory...
Hi

I have moved my website from a server to another one and I have to do a mass replace in all the files in my cgi-bin directory (and in all the directories wich are in cgi-bin)

I have to replace the following string :
#!/usr/local/bin/perl

by the following one :
#!/usr/bin/perl

How to do it ? via a shell command? if yes what is this command ?

Regards
FMP
Quote Reply
Re: [fmp] mass replace in a directory... In reply to
In SSH/Telnet, type;

cd /path/to/your/admin
grep -r -l '#!/usr/local/bin/perl' .

...and when you are happy this is the list of files you want to modify, then run;

perl -p -i -e 's|\Q#!/usr/local/bin/perl|#!/usr/bin/perl|g' `grep -r -l '#!/usr/local/bin/perl' .`

Hope that works Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] mass replace in a directory... In reply to
txs Wink

it works fine

FMP
Quote Reply
Re: [Andy] mass replace in a directory... In reply to
Hello,

I want to change paths in all cgi files in my account. Can I just use the following command from root to change paths in all my cgi files, like so?

perl -p -i -e 's|/home/www/site/path/|/home/www/newsite/newpath/|g' *.cgi

Will that work?

Thanks in advance!!!
Quote Reply
Re: [socrates] mass replace in a directory... In reply to
Nope, you would need:

Code:
perl -p -i -e 's|/home/www/site/path/|/home/www/newsite/newpath/|g' `grep -r -l '/home/www/site/path/' .`

Doing *.cgi would only find files in that same folder =)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] mass replace in a directory... In reply to
Andy,

How about if I also want to change paths to all my files in my WWW directory?

Thanks!
Quote Reply
Re: [socrates] mass replace in a directory... In reply to
Just 'cd' to your www folder, with something like:

Code:
cd ./domain.com/www

..and then run the other command (the "grep" one)

Grep will only run inside the fodler you are in.

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates