Tôi có hai tập tin: file1và file2.
file1 có nội dung như sau:
---
host: "localhost"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "localhost:2181"
file2chứa địa chỉ IP ( 1.1.1.1)
Những gì tôi muốn làm là thay thế localhostbằng 1.1.1.1, để kết quả cuối cùng là:
---
host: "1.1.1.1"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "1.1.1.1:2181"
Tôi đã thử:
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
Nhưng tôi có thể thay thế toàn bộ dòng hoặc IP sẽ chuyển sang dòng sau khi tôi cần sửa đổi.
\rlệnh sed.
cat file1 | sed -e 's/localhost/1.1.1.1/g'làm việc?