Global Find Replace Whole Directory

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Global Find Replace Whole Directory

Post by Ollie Saunders »

I want to find and replace a string for another in a whole directory of files. Pretty simple really.
I have access to PHP, linux commands and Windows software.

Any simple suggestions?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Sorry, I don't get what you want. Can you be more specific please?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

I have 30 PHP files in a directory.
I want to find all instances of 'OsisForm' within the files and replace it with 'OF'
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Be sure to chmod a+x it..

replace.sh

Code: Select all

for fl in *.php; do
mv $fl $fl.old
sed 's/OsisForm/OF/g' $fl.old > $fl
#rm -f $fl.old
done
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

worked a treat astions.
thanks.
Post Reply