0

i have special characters in the content of $VALUE which I would to add in file ($FILE).

When I run this cammand :

sed -i "s|T_VALUE|$VALUE|" "$FILE"

i have an error unterminated s command

i saw some post saying i need to escape the special characters, but i do not know them upfront as $VALUE is a dynamic value. how can i solve this?

Romeo Ninov
  • 17,484
akaliza
  • 101

1 Answers1

2

You can use Perl for fancier quoting. To avoid confusion, you can pass arguments via environment variables.

$ SUB_LH='?|'
$ SUB_RH='/\'
$ cat mydata.txt
x?|y
?|ab?|
$ SUB_LH=$SUB_LH SUB_RH=$SUB_RH perl -p -i.bak -e 's/\Q$ENV{SUB_LH}\E/$ENV{SUB_RH}/g' mydata.txt
$ cat mydata.txt
x/\y
/\ab/\
don_aman
  • 1,373