Computing.Net > Forums > Unix > Sed and IP addresses...

Sed and IP addresses...

Reply to Message Icon

Original Message
Name: maddoudou22
Date: September 9, 2004 at 08:00:34 Pacific
Subject: Sed and IP addresses...
OS: Linux Debian
CPU/Ram: Pentium2 RAM:64Mo
Comment:

I am trying to make a tricky substitution with sed:

I have a file 'test.txt' with the following records:
address: 192.168.120.1
other: 192.168.120.15
list: 2here: 192.168.120.1;192.168.120.2
files: list: 2here: //192.168.120.1/files

I would like to change all the 192.168.120.1 occurences with 129.181.231.23


For this, I use the following command:
sed -e 's/192\.186\.120\.1/129\.181\.231\.23/g' test.txt > newtest.txt

But the problem is that the second line is then replaced by this one:
other: 129.181.231.235


No problem, but if I use the following command:
sed -e 's/192\.186\.120\.1[^0-9]/129\.181\.231\.23/g' test.txt > newtest.txt

The ';' disapears in the third line and the '/' disapears too in the last line!


What I would like to do is checking the character that follows a string without replacing or deleting it.

I have no more ideas. Is it possible to do such a thing with only one sed command? If not, any ideas?


Thanks !


Report Offensive Message For Removal


Response Number 1
Name: Wolfbone
Date: September 9, 2004 at 09:02:34 Pacific
Subject: Sed and IP addresses...
Reply: (edit)

sed -e 's/\(.*\)\(192\.168\.120\.1\)\([^0-9].*\|$\)/\1129\.181\.231\.23\3/g'


Report Offensive Follow Up For Removal

Response Number 2
Name: maddoudou22
Date: September 10, 2004 at 00:12:32 Pacific
Subject: Sed and IP addresses...
Reply: (edit)

It works great
Thanks a lot!

Thanks !


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Sed and IP addresses...

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software