Ich habe zwei Dateien: file1und file2.
file1 hat folgenden Inhalt:
---
host: "localhost"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "localhost:2181"
file2enthält eine IP-Adresse ( 1.1.1.1)
Was ich will , ist zu tun , ersetzen localhostmit 1.1.1.1, so dass das Endergebnis ist:
---
host: "1.1.1.1"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "1.1.1.1:2181"
Ich habe versucht:
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
Aber ich bekomme entweder die ganze Leitung ersetzt, oder die IP geht auf die Leitung nach der, die ich ändern muss.
\rsed Befehl an.
cat file1 | sed -e 's/localhost/1.1.1.1/g'?