I have a problem. I would like replace a line of a file by the content of another file.
In my first file I have this line: "#Content"
and I would like to replace that with the content of the file content.xml
.
Thanks.
This can work:
your_new_text=$(cat content.xml | sed 's/[^-A-Za-z0-9_]/\\&/g')
sed -i "s/#Content/$your_new_text/" your_file
It puts the text from content.xml
in the variable $your_new_text
. Then sed does the work: -i
stands for replacing in the file, looks for #Content
and replaces by text inside $your_new_text
.
Note that it has to be wrapped with "
to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With