views:

60

answers:

3

I've got a database dump in MySQL where I want to replace ocurrencies of paths that are in the dump as plaintext.

In this particular case I'd like to replace:

/var/www/

for

/home/www/

How could I safely do that using cat or any other shell tool?

+2  A: 
cat old.file | sed 's%/var/www/%/home/www/%g' > new.file
Bolo
useless use of cat
ghostdog74
Is the only one that worked in any case.
Cy.
The cat can be "optimized away", of course. However, I prefer to leave it as it is for two reasons. 1) This solution also works when the dump comes from standard output of a process instead of a file. 2) It clearly shows that old.file is only read, but not written.
Bolo
+1  A: 

Try:

sed 's/\/var\/www\//\/home\/www\//' old_file > new_file
codaddict
A: 
awk '{gsub("/var/www/","/home/www/")}1' mydump >temp && mv temp mydump
ghostdog74