Report

Sed find and replace ip addresses in a file [Closed]

Ask a question nick - Last answered on Aug 15, 2009 at 09:52 AM by jipicy
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.
See more 
Helpful
+2
plus moins
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$
;-))
Was this answer helpful?  
Helpful
+0
plus moins
Hi,

What is the common pattern ? 044 or 10.1.10.200 ?

Member requests are more likely to be responded to.

Members can monitor the statuses of their requests from their account pages.

A CCM membership gives you access to additional options.

Not a member yet?

Sign up now. It takes less than a minute and is completely free!