Reputation: 4300
I would like to know how to find and replace text in all HTML, htm, PHP and txt extension files on Linux server at hosting provider. I can do SSH.
Text to be found:http://mydomain.example.com
Text to be replaced with:http://otherdomain.example.com/MyDomain
Please give me exact command and it would be much helpful if it can prompt for confirmation before replacement.
Upvotes: 1
Views: 1042
Reputation: 54512
Here's one way using sed
and a for
loop. Use the -i
flag with mv
to prompt before overwrite:
for i in *.html *.htm *.php *.txt; do sed 's%\(http://www\.\)\(MyDomain\)\(\.com\)%\1OtherDomain\3/\2%g' "$i" > tmp && mv -i tmp "$i"; done
Upvotes: 3
Reputation: 944
sed -i 's/http:\/\/www.mydomain.com/http:\/\/www.otherdomain.com\/MyDomain/gi' *.txt *.html *.htm *.php
Upvotes: 0