मेरे पास दो फाइलें हैं: file1और file2।
file1 निम्नलिखित सामग्री है:
---
host: "localhost"
port: 3000
reporter_type: "zookeeper"
zk_hosts:
- "localhost:2181"
file2एक आईपी पता शामिल है ( 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
लेकिन मुझे या तो पूरी लाइन बदलनी है, या जिस आईपी को मैं संशोधित करने की आवश्यकता है उसके बाद लाइन पर जा रहा हूं।
\rsed कमान।
cat file1 | sed -e 's/localhost/1.1.1.1/g'काम करता है ?