-1

I want that file :

#ansible_python_interpreter=/usr/bin/python3 [win] #s1 192.168.1.148 #s2

to be like this :

#ansible_python_interpreter=/usr/bin/python3 [win] #s1 127.0.0.1 #s2

Im typing :

sed -e '/#s1/,/#s2/c\#s1\n127.0.0.12\n\#s2' hosts

OK, but I want the address from another file called tmp_ip : 10.0.0.1 for example but it can be any address present in it.

What could i do ?

Luca
  • 3
  • 1

1 Answers1

1

Using sed

$ sed -E "s/([0-9]+\.[0-9]+?)+/$(cat tmp_ip)/" input_file
#ansible_python_interpreter=/usr/bin/python3 [win] #s1 127.0.0.1 #s2

Or if the pattern must be matched

$ sed -E "s/(#s1 )[^#]*/\1$(cat tmp_ip) /" input_file
#ansible_python_interpreter=/usr/bin/python3 [win] #s1 127.0.0.1 #s2
HatLess
  • 10,622
  • 5
  • 14
  • 32