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

Report
-
jipicy
Posts
43481
Registration date
Wednesday August 27, 2003
Status
Moderator
Last seen
December 5, 2019
-
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.

2 replies

Posts
43481
Registration date
Wednesday August 27, 2003
Status
Moderator
Last seen
December 5, 2019
17
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$
;-))
2
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 4131 users have said thank you to us this month

Posts
43481
Registration date
Wednesday August 27, 2003
Status
Moderator
Last seen
December 5, 2019
17
Hi,

What is the common pattern ? 044 or 10.1.10.200 ?