I have two different files:
File1
/home/user1/
/home/user2/bin
/home/user1/a/b/c
File2
<TEXT1>
<TEXT2>
I want to replace the <TEXT1>
of File2 with the contents of File1 using sed
. I tried this command, but not getting proper output:
cat File2|sed "s/<TEXT1>/$(cat File1|sed 's/\//\\\//g'|sed 's/$/\\n/g'|tr -d "\n")/g"
You can use other tools also to solve this problem.
sed
implementation are you using. You code works for me with GNUsed
. – manatwork Sep 08 '11 at 14:40/home/user1/ n/home/user2/bin n/home/user1/a/b/cn <TEXT2>
. Not getting new lines. – chanchal1987 Sep 08 '11 at 14:51diff
andpatch
tools allow to replace some lines in a file by other lines quite easily. – Stéphane Gimenez Sep 08 '11 at 14:54$()
in a sed script makes my eyes bleed. Never use external data in places where some characters are interpreted with special meaning. – Stéphane Gimenez Sep 08 '11 at 14:59