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!
See if this works.
var="MRD"
sed 's/ABC/&\n'"${var}"'/' text.txt
EDIT
We can use any character instead of /. So if we expect it to be in the search or replace expression, use |
var="</stuff>"
sed 's|ABC|&\n'"${var}"'|' text.txt
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