I have two files file1 & file2.
Contents of file1:
Text1
Text2
Text3
Contents of file2:
Sample1
Sample2
Sample3
I would like to replace the word Text1 from file1 with the contents of file2. I already tried the below commands:
sed -i 's/Text1/r file2/g' file1
sed -e 's/Text1/`cat file1`/' < file2
Neither of which worked, what am I missing?
sedor would anawksolution be OK, too? – Hauke Laging Feb 05 '15 at 14:07awkorsed– Thushi Feb 05 '15 at 14:07cp file2 file1should work. If this is not the case, please clarify your question. – jordanm Feb 05 '15 at 14:21awk,ed, andsedare all well represented. All three answers not only provide workable solutions, but also describe how and why the solutions are workable. – mikeserv Feb 06 '15 at 05:55sed -i '/Text1/r file1' file2sed -i '/Text1/d' file2– Thushi Feb 06 '15 at 06:13