-1

My variables issuer and subject contains

issuer=C=IN,ST=TN,L=XYZ,O=ABC,OU=CA,CN=XYZ.com/emailAddress=xyz@gmail subject=C=GB,ST=London,L=London,O=Global_Security,OU=IT,CN=example.comCA/emailAddress=acl@123

I want to replace a variable leftid and leftca with subject and issuer in xyz.conf respectively.

I'm using sed command like this

sed -i -e '/leftid=/s/=.*/= '$subject'/' /etc/xyz.conf

and

sed -i -e '/leftca=/s/=.*/= '$issuer'/' /etc/xyz.conf

But I'm getting the following error(s)

sed: -e expression #1, char 66: unknown option to s' sed: -e expression #1, char 83: unknown option tos'

Can anyone help?

Yannick
  • 813
  • 8
  • 17
  • 2
    pick a delimiter that is not part of the string for sed s command. There are / in both strings. – strobelight Nov 07 '17 at 11:57
  • 2
    Does this answer your question? [How to pass a variable containing slashes to sed](https://stackoverflow.com/questions/27787536/how-to-pass-a-variable-containing-slashes-to-sed) – tripleee Sep 25 '20 at 09:28

1 Answers1

0

Your $issuer variable is expanded in the sed substitution part and so the expression becomes:

sed -i -e '/leftca=/s/=.*/= 'C=IN,ST=TN,L=XYZ,O=ABC,OU=CA,CN=XYZ.com/emailAddress=xyz@gmail'/' /etc/xyz.conf

and this is not a correct sed expression since there is 4 occurrences of the / delimiter.

To sum up your sed command is right just change the s substitution command separator with something not present in your issuer variable, like for instance:

sed -i -e '/leftid=/ s|=.*|= '$subject'|' /etc/xyz.conf
hi olaf
  • 227
  • 1
  • 5