0

I have a file I want to edit.

at the beginning, I take another file, I add for each line "\0A", I delete the end-of-line characters, and I put it in an OV variable

OV=$(cat certificate_file | sed  's/$/\\OH/' | tr -d '\n')   #Add \OH + delete end of 
                                                              line caracter

Now I want to replace the contents of the config_var1= variable in the conf file, with what is in OV

I tried to use this command:

sed -i -r "s:config_var1=.*:config_var1=$OV:g" config_file

but it doesn’t work because I have a line like this in the OV vriable :

8d:c8:c7:r5:m8:e1:ub:f3:09:2s:c1:5a:7a:b7:c0:cb

so i got this error :

sed: -e expression #1, char 2239: unknown option to `s'
lystack
  • 41
  • 4

1 Answers1

1

sed can use any character as a separator between the regex and the replacement. Choose some character that does not appear in $OV. For example:

sed -i -r "s#config_var1=.*#config_var1=$OV#g" config_file

If all of the characters are used and your script is running on Bash (non-POSIX), you can use substitution while expanding the variable and replacing the delimiter to escape it with the ${var/exp/subst} syntax. If your delimiter is @, you should do it like this: ${OV/@/\\@}. Note the double backslash to display a literal backslash.

CoderCharmander
  • 1,862
  • 10
  • 18