Replacing text with another text in a certain directory recursively using a bash script

Greetings,

I want a shell script that can replace a text with another text for special file types (*.html, for an instance) in a certain directory recursivle. The modified file has of course to be in the same location of the original file.

Thanks,
Hossam
mBfAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ahoffmannCommented:
find . -type f -name \*.html|xargs perl -i.bak -pe 's/lamb/sheep/g'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mBfAuthor Commented:
Works.
Suppose that I want to change www.domain1.com to www.domain2.com..
Would it be: find /root/test -type f -name \*.html|xargs perl -i.bak -pe 's/www.domain1.com/www.domain2.com/g' without any escape characters?

Cheers,
Hossam
0
mBfAuthor Commented:
Also, instead of "." should I enter the directory name as "/directory/path/" or "/directory/path/."?
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

ahoffmannCommented:
find /root/test -type f -name \*.html|xargs perl -i.bak -pe 's/www\.domain1\.com/www.domain2.com/g'
# more perfect
0
mBfAuthor Commented:
When I test this script it works well, but when I use it in a real life situation it does not modify the files nor produce .bak ones. Very weird!

Any suggestions?
0
ahoffmannCommented:
sounds like your real life data does not match your test requirements :-))
you have to change one of them ..
0
mBfAuthor Commented:
Got it.. For some reason this command does not follow symlinks.
Thanks, ahoffmann and much appreciated

--Hossam
0
ahoffmannCommented:
for symlinks you have to check find's docs, symlinks, mount points and -prune are the dragons to beat on each platform :-(
0
mBfAuthor Commented:
Maybe on my vacation ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.