Saya punya dua file: file1dan file2.
file1 memiliki konten berikut:
---
host: "localhost"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "localhost:2181"
file2berisi alamat IP ( 1.1.1.1)
Yang ingin saya lakukan adalah mengganti localhostdengan 1.1.1.1, sehingga hasil akhirnya adalah:
---
host: "1.1.1.1"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "1.1.1.1:2181"
Saya telah mencoba:
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
Tapi saya bisa mengganti seluruh baris, atau IP ke baris setelah saya perlu memodifikasi.
\rperintah sed.
cat file1 | sed -e 's/localhost/1.1.1.1/g'berhasil?