Inserting text in a file from a variable
- by user754905
I have a file that looks something like this:
ABC
DEF
GHI
I have a shell variable that looks something like this:
var="MRD"
What I want to do, is to make my file look like this:
ABC
MRD
DEF
GHI
I was trying to do this:
sed -i -e 's/ABC/&$var/g' text.txt
but it only inserts $var instead of the value. I also tried this:
sed -i -e 's/ABC/&"$var"/g' text.txt
but that didn't work either. Any thoughts?
Thanks!