Ask a question Report

Sed find and replace ip addresses in a file

nick - Latest answer on Aug 15, 2009 09:52AM
Hello,
What is the easiest way to replace a couple of IP addresses on the same line separated by a space in a bunch of files called *.out?
i.e.
file1.out
044=10.1.10.200 10.2.10.200
want to replace them with
044=192.168.1.200 192.168.2.200
Thanks,
nick.
Read more 
Answer
+2
moins plus
jp@MDK:~/tmpfs ssh$ cat file1.out
044=10.1.10.200 10.2.10.200

jp@MDK:~/tmpfs ssh$ sed '/^044/ s/=.*/=192.168.1.200 192.168.2.200/' file1.out
044=192.168.1.200 192.168.2.200

jp@MDK:~/tmpfs ssh$ sed -i.bak '/^044/ s/=.*/=192.168.1.200 192.168.2.200/' file1.out

jp@MDK:~/tmpfs ssh$ cat file1.out
044=192.168.1.200 192.168.2.200

jp@MDK:~/tmpfs ssh$ cat file1.out.bak
044=10.1.10.200 10.2.10.200

jp@MDK:~/tmpfs ssh$
;-))
Add comment
Answer
+0
moins plus
Hi,

What is the common pattern ? 044 or 10.1.10.200 ?
Add comment
This document entitled « Sed find and replace ip addresses in a file » from Kioskea (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.

Not a member yet?

sign-up, it takes less than a minute and it's free!

Members get more answers than anonymous users.

Being a member gives you detailed monitoring of your requests.

Being a member gives you additional options.