this helpful tidbit is for readers with perl installed on their computers that need to perform a find-replace on entirely too large of an SQL file. on a mac you can find out if you have perl by checking for the version:
if something shows up like “This is perl 5, version 18, subversion 2, etc. etc. etc.”, congrats, you have perl!
the other day i was exporting a monster wordpress site and needed to do a find-replace on the entire database before importing again. the sql file was a tad large, and by that i mean it crashed my Sublime Text Editor. it also crashed a regular text editor and Coda. so i did what i always do when my programs fail me: to the command line!
after some increasingly specific google searches to figure out how to use anything (anything) available to me on the command line to find-replace on a single file, i found this handy little perl command (make sure you’re in the correct directory):
perl -pi -w -e 's/SEARCH_FOR/REPLACE_WITH/g;' filename.txt
if you’re like me and are replacing URLs, you may want to remember that you’ll have to escape some characters with backslashes, including forward slashes. for example, if i wanted to replace ‘example.com/blog’ with ‘exampleblog.com’, my command would read as follows:
perl -pi -w -e 's/example.com\/blog/exampleblog.com/g;' filename.txt
that did the trick! so much faster too.