I'm trying to add some text (a path) at the end of a line which is found by a sed command:
var="/folder1/folder2/folder3"
sed -i "/Begins with this text/s/$/$var/" filename
I know that double quotes are needed to use variables in a sed command but if I use the above command it gives me an error message saying:
expresssion #1, character 23: unknown option to `s
What am I doing wrong?
Change the delimiter in the substitute command to something that won't appear in $var
, e.g.
sed -i "/Begins with this text/s|$|$var|" filename
or escape the slashes in $var
:
var="\/folder1\/folder2\/folder3"
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