mBf
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Also, instead of "." should I enter the directory name as "/directory/path/" or "/directory/path/."?
find /root/test -type f -name \*.html|xargs perl -i.bak -pe 's/www\.domain1\.com/www.domain2.com/g'
# more perfect
# more perfect
ASKER
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?
Any suggestions?
sounds like your real life data does not match your test requirements :-))
you have to change one of them ..
you have to change one of them ..
ASKER
Got it.. For some reason this command does not follow symlinks.
Thanks, ahoffmann and much appreciated
--Hossam
Thanks, ahoffmann and much appreciated
--Hossam
for symlinks you have to check find's docs, symlinks, mount points and -prune are the dragons to beat on each platform :-(
ASKER
Maybe on my vacation ;)
ASKER
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