Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the fastest / most efficient find/replace app on *nix

I've got a large SQL dump 250MB+ and I need to replace www.mysite with dev.mysite. I have tried nano and vi for doing find/replace but both choke. Nano can't even open it, and vi has been doing the find/replace now for an hour.

Anyone know of a tool on *nix or windows systems that does fast Find/Replace on large files?

like image 969
Alexandru Petrescu Avatar asked Dec 13 '22 16:12

Alexandru Petrescu


2 Answers

sed -i 's/www\.mysite/dev.mysite/g' dump.sql

(requires temporary storage space equal to the size of the input)

like image 62
ephemient Avatar answered Jan 10 '23 23:01

ephemient


Search/replace on a SQL dump is not a good idea

  • They aren't text files
  • SQL syntax errors are easily introduced
  • They contain very long lines sometimes.

What you should do is load it into a non-production database server, run the appropriate UPDATE statements then dump it again. You can use the REPLACE function in MySQL for this.

like image 43
MarkR Avatar answered Jan 10 '23 22:01

MarkR