Inserting text in a file from a variable

Posted by user754905 on Stack Overflow See other posts from Stack Overflow or by user754905
Published on 2012-04-10T23:17:09Z Indexed on 2012/04/10 23:28 UTC
Read the original article Hit count: 218

Filed under:
|
|
|

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!

© Stack Overflow or respective owner

Related posts about osx

Related posts about bash