UNIX Command Needed: How do I perform search/replace word on all html pages in subfolders

I'm trying to write a simple command that will perform search/replace for a word in all html (*.htm,*.html) files in all sub-folders.

I wrote this command, but it will only search within folder:

perl -pe 's/<search>/<replace>/g' *.htm*

Who is Participating?
arnoldConnect With a Mentor Commented:
find goes through the directory structure.
is perl in your path?
which perl/
replace perl with /usr/bin/perl

alterantively, you can do
find . -name "*.html" | xargs perl -i.bak -ep 's/pattern/replacemenet/g'
perl -i.bak -p -e 's/searchpattern/replacementpattern/'  *.html */*.html.
another option is to use find
find . -name "*.hml" | while read a; do
perl -i.bak -pe 's/<search>/<replace>/g' $a
The -i.bak will create a backup file of the one being changed and saved as file.html.bak

find . -name "*.html" -exec perl -i.bak -ep 's/pattern/replacemenet/g' {}\;
could work provided there aren't too many files.

maheflin25Author Commented:
Thanks for your solution, however it does not cover files in its subdirectories.

When I tried this command: find . -name "*.html" -exec perl -i.bak -ep 's/pattern/replacemenet/g' {}\;

I get an error message: find: missing argument to '-exec'

All Courses

From novice to tech pro — start learning today.