Results 1 to 2 of 2
Hi I found this command that works great finding and replacing a simple string to another in files located in that folder and all sub-folders. Code: find . -name '*.php' ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-11-2010 #1
- Join Date
- Nov 2005
Command for Find/Replace in text files (inc. files in sub-folders)
find . -name '*.php' | xargs perl -pi -e 's/OldText/NewText/g'
Old string: /mnt/stor6-wc2-dfw1/627896/982574/
New string: /mnt/stor8-wc2-dfw1/369587/302589/
There I don't know how to do it... since the / is what separates the old from the new strings, and the strings that I want to replace have / in it.
Also, I would like to know how to specify under what folder replace the files, for example, I want that it search/replaces all files under /var/www/mysite/htdocs folder.
All help is welcomed... thanks!
- 10-12-2010 #2
- Join Date
- Mar 2009
Change the / separator to a character that doesn't appear in the strings like |:
find . -name '*.php' | xargs perl -pi -e 's|OldText|NewText|g'
find /var/www/mysite/htdocs -mindepth 2 -name '*.php' | xargs perl -pi -e 's|OldText|NewText|g'