I have a sql file of a wordpress database. I am moving to another server which the document root is different.

The old document root was /home/saeid/public_html

The new document root is /home/saeid/www/domain.com/html

I want to replace all the occurrences of old path with new path.

I have seen this example which replaces foo with bar...but as I want to replace path which itself has "/" characters in it...I am not sure if it would the job. sed -i -e 's/foo/bar/g' filename


Just use a different delimiter:

sed -i 's|foo|bar|g' filename

So, in your case:

sed -i 's|/home/saeid/public_html|/home/saeid/www/domain.com/html|g' file

This is mentioned in info sed:

The syntax of the s (as in substitute) command is ‘s/regexp/replacement/flags’. The / characters may be uniformly replaced by any other single character within any given s command. The / character (or whatever other character is used in its stead) can appear in the regexp or replacement only if it is preceded by a \ character.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.