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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Sed and IP addresses...

Reply to Message Icon

Name: maddoudou22
Date: September 9, 2004 at 08:00:34 Pacific
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 !



Sponsored Link
Ads by Google

Response Number 1
Name: Wolfbone
Date: September 9, 2004 at 09:02:34 Pacific
Reply:

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


0

Response Number 2
Name: maddoudou22
Date: September 10, 2004 at 00:12:32 Pacific
Reply:

It works great
Thanks a lot!

Thanks !


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Unowned accounts ksh yyddd (julian date) t...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Sed and IP addresses...

Changing domains and IP addresses www.computing.net/answers/unix/changing-domains-and-ip-addresses/5494.html

IP Address problem www.computing.net/answers/unix/ip-address-problem/1386.html

printing to an ip address www.computing.net/answers/unix/printing-to-an-ip-address/3463.html