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' ...
- 10-11-2010 #1Just Joined!
- Join Date
- Nov 2005
- Posts
- 5
Command for Find/Replace in text files (inc. files in sub-folders)
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.
The problem I have is that I need to replace a more complex string, like this:Code: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 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
Change the / separator to a character that doesn't appear in the strings like |:
Use the -mindepth 2 option. The find would look like:Code:find . -name '*.php' | xargs perl -pi -e 's|OldText|NewText|g'
Code:find /var/www/mysite/htdocs -mindepth 2 -name '*.php' | xargs perl -pi -e 's|OldText|NewText|g'


Reply With Quote