ฉันมีสองไฟล์: และfile1file2
file1 มีเนื้อหาดังต่อไปนี้:
---
host: "localhost"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "localhost:2181"
file2มีที่อยู่ IP ( 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 ไปที่บรรทัดหลังจากที่ฉันต้องการแก้ไข
ดูที่
—
Kevin
\rคำสั่ง sed
cat file1 | sed -e 's/localhost/1.1.1.1/g'ทำงานได้หรือไม่