Help - Search - Members - Calendar
Full Version: Unix search and replace, multiple files and multiple directories
The Planet Forums > Operating Systems > Red Hat Linux > Red Hat HOWTOs
mmt
I am looking for a way to create a script that can do a search and replace on all html files in a directory and all subdirectories.

I have found out how to do it in all the files in a directory, but not how to include the subdirectories.

Any help would be appreciated. Here is what I have to replace one string with another on all .htm files in a directory, the question really is how do I make it include directories under the current directory?

perl -i -pe 's/replacethis/withthat/g' *.htm
Catalyst
CODE
perl -i -p -e 's/replacethis/withthat/g' `find | grep .htm`
Note those are backwards apostrophes.
edornano
I did not originally ask the question, but that was very helpful. Thanks.
Manuel
I think below mentioend URL will also help:

http://forums.linuxwebadmin.info/index.php...topic,35.0.html
Master Resale Rights
QUOTE (Manuel @ Sep 6 2006, 10:17 AM) *
I think below mentioend URL will also help:

http://forums.linuxwebadmin.info/index.php...topic,35.0.html


I agree with you, this link is very helpful. Thanks for sharing this dude!
universal
Much appreciated for the URL, the link is helpful but i'm still having a little trouble with it icon_sad.gif but I now have all the information that I need so it should be pretty straightforward!!

So thanks for the help here guys icon_smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.