This question from another user was wrongfully marked duplicate, so I'm posting it again, emphasising the problem.
I´m trying to set in one of my xml files a private key which is save in a an external repository for security reasons. This is my bash script
sed -i -e "s/privateKey/`cat privatekey`/g" text.txt
Where privateKey is my key downloaded from a repository and text.txt contains
<test>
privateKey
</test>
After run the script I was expecting this:
<test>
-----BEGIN RSA PRIVATE KEY-----
privatekeyblablablablafoooo
-----END-----------
</test>
But because of the contains of the private key sed is getting me this error
sed: 1: "s/privateKey/-----BEGIN ...": unescaped newline inside substitute pattern
Any idea how can I escape the new line characters, that are coming in from the cat command?