Last Updated: February 25, 2016
· jwebcat

use sed -i to replace in place on a string in a file

use this handy bit to replace in place a string in a file.

sed -i 's#string#otherstring#g' filename

and you will be replacing strings with ninja speed.

I use this to keep my database in sync with WordPress

  • Just make sure that you that your dev url and your production url are the same length otherwise you will have serialization issues. (namely all the widgets and their settings)

  • In order to avoid this caveat of monkeypatching my sql file, I make an entry in my host file to have both urls the same length. e.g.

and then an entry in my apache virtual hosts file to redirect to localhost/sites/somewebsite

dev url:

production url:

and then it plays nice with WordPress just dandy.