-2

I wan to replace a specific IP to another so say localhost to 0.0.0.0

sed -i -e 's/localhost/0.0.0.0/g' doesn't seem to work

also tried sed -i -e 's/localhost/0\.0\.0\.0/g' doesnt work either

sed: RE error: illegal byte sequence

user1870400
  • 6,028
  • 13
  • 54
  • 115

1 Answers1

1

Your examples seem to work fine for me. Given the following test.txt

ip=localhost

The following replaces the entire ip=localhost with 0.0.0.0

sed -i -e 's/ip=localhost/0\.0\.0\.0/g' test.txt

If you just want the localhost part replaced:

sed -i -e 's/localhost/0\.0\.0\.0/g' test.txt

will give you the following:

 ip=0.0.0.0
djsumdog
  • 2,560
  • 1
  • 29
  • 55
  • I want to replace every file that has localhost with 0.0.0.0 and it says Sed ERR illegal byte sequence with all of them I tried. find ./ -type f -exec sed -i -e 's/ip=localhost/0\.0\.0\.0/g' {} \; and find ./ -type f -exec sed -i -e 's/localhost/0\.0\.0\.0/g' {} \; – user1870400 May 04 '16 at 23:16
  • 2
    Your original question didn't mention the find. You need to include all the relevant information in your question. You can either update your question or start a new one. – djsumdog May 04 '16 at 23:44