I have a yaml file that needs to be updated with string containing special characters. Here is the command I used but I get sed expression error
Yaml file (file):
Command that works without special characters for $var (env variable):
sed -i '0,/^([[:space:]]*Key1: *).*/s//1'$var'/;' file
Value for $var:
Error I get is:
sed: -e expression #1, char 154: unknown option to `s'
I am trying to figure out how I can get this working. Any help is greatly appreciated. Thanks!
The default delimiter of
sed is conflicting with the
/ in your variable. You will need to set a different delimiter, further, the single quotes will not allow the variable to expand.
You can try this
$ sed "|Key1|s|$|'$var'|" input_file Key1: 'fkugoiuhoiuyflkbbui/qy++bfv7J3c' Key2: