I have two files: file1 and file2.
file1 has the following contents:
---
host: "localhost"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "localhost:2181"
file2 contains an IP address (1.1.1.1)
What I want to do is replace localhost with 1.1.1.1, so that the end result is:
---
host: "1.1.1.1"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "1.1.1.1:2181"
I have tried:
sed -i -e "/localhost/r file2" -e "/localhost/d" file1
sed '/localhost/r file2' file1 |sed '/localhost/d'
sed -e '/localhost/r file2' -e "s///" file1
But I either get the whole line replaced, or the IP going to the line after the one I need to modify.
cat file1 | sed -e 's/localhost/1.1.1.1/g'work?\rsed command.sed.rcommand for sed that does this and is way easier to implement and has no issues with / in the file. unix.stackexchange.com/a/32912/201387