PDA

View Full Version : simple sed question


waiting_for_OSX
September 7th, 2009, 03:32 PM
What is wrong with this bash command?

$ sed -i 's/localhost/myurl/g' myfile.php
sed: 1: "myfile.php": command a expects \ followed by text

Why doesn't this work to replace localhost with myurl in all php files?

$ sed -i 's/localhost/myurl/g' *.php
sed: 1: "myfile.php": command a expects \ followed by text

I'm using Snow Leopard.

gamemaniac
September 11th, 2009, 02:12 AM
Your question have just left me confused a little. Perhaps I know the answer but not sure right now.

ElDiabloConCaca
September 11th, 2009, 11:53 AM
The -i requires that you give an extension, even if it's a non-existent extension (for in-place editing).

Change the command to this:

sed -i '' 's/localhost/myurl/g' myfile.php
...and see if that works for you. Be aware that in-place editing will perform the edits on the files you specify without making backup copies, so it's dangerous in the sense that a malformed regex can permanently change the files you're working on without making backups of them.

gamemaniac
September 12th, 2009, 01:46 AM
Thanks ElDiabloConCaca that's what was not coming to my mind?