Tonight we were switching a clients WordPress site to a new domain name and in the process found some of the old domain was hard coded into PHP files. There were too many to try and sort through them, plus I was likely to miss something. I knew a script was needed. My Google-fu was weak, I tried some posted tips on how to do this using perl and php commands but found they didn’t work in our environment. Finally I remembered a tool we used to search and insert scripts in the hosted PBX environment I used to maintain. sed. I found good old sed worked best for this:
sed -i ‘s/OLD TEXT TO REPLACE/NEW TEXT TO REPLACE/g’ *.php
Try it out for yourself, and of course an obligatory shout out to my cousin Gabe Anderson for posting a perl script that worked for him 4 years ago.