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? – dchirikov Jul 08 '14 at 18:57\r
sed command. – Kevin Jul 19 '14 at 15:01sed
. – MayeulC May 02 '23 at 12:59r
command for sed that does this and is way easier to implement and has no issues with / in the file. https://unix.stackexchange.com/a/32912/201387 – DKebler May 15 '23 at 15:05