Link to home
Start Free TrialLog in
Avatar of maheflin25
maheflin25

asked on

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*

Thanks,
Avatar of arnold
arnold
Flag of United States of America image

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
done
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.

Avatar of maheflin25
maheflin25

ASKER

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'

Regards,
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial