2つのファイルがあります:file1とfile2。
file1 次の内容があります。
---
host: "localhost"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "localhost:2181"
file2IPアドレスが含まれています(1.1.1.1)
私がしたいのは、に置き換えlocalhostて1.1.1.1、最終結果が次のようになることです:
---
host: "1.1.1.1"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "1.1.1.1:2181"
私が試してみました:
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
ただし、行全体を置き換えるか、変更する必要があるIPの後に行にIPを移動します。
\rsedコマンドを見てください。
cat file1 | sed -e 's/localhost/1.1.1.1/g'動作しますか?