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,
I wrote this command, but it will only search within folder:
perl -pe 's/<search>/<replace>/g' *.htm*
Thanks,
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,
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.