I have just found a really helpful command that I can see myself using all the time. It’s too often that I need to take a copy of a development database file and update the absolute paths to use the live address.
Imagine you have a .sql file that you have created by exporting a wordpress database. That can be done using the mysqldump command over the command line in Linux/Ubuntu. Now you want to replace all (global) occurrences of “local” with “live” in a file called “data.sql” and catch the results in a new file called “new.sql” the code would be as follows.
sed -e 's/local/live/g' data.sql > new.sql
A new file should be created called “new.sql” with the replacements made. SED is a tool available in all Linux distributions and can be accessed via the command line. The “e” command runs the function with the script that follows in quotes. The ‘s’ command treats the arguments as separate files. The ‘g’ means global. This makes a replacement on multiple lines.
This is an interpretation based on guidance from this following article it’s a very simple example. For my own reference really, but I hope you find useful.