0

I have a file named config.yaml that contains this line:

device_connection_string: "<ADD DEVICE CONNECTION STRING HERE>"

I want to replace <ADD DEVICE CONNECTION STRING HERE> with the value of the following variable:

root@ubuntu1804-ko-001:/tmp# echo "$CSTRING"

HostName=PulseAzure-BetterTogetherDemo.azure-devices.net;DeviceId=ubuntu1804-ko-001;SharedAccessKey=xdWDu2gnzlg8X1mHgGqYU+yECBYUJ065n1AjdkYNCWI=
root@ubuntu1804-ko-001:/tmp#

When I run this sed command, I get the unterminated s error:

sed -i "s/<ADD DEVICE CONNECTION STRING HERE>/$CSTRING/g" config.yaml
sed: -e expression #1, char 38: unterminated `s' command

Thank you for your help!

  • 1
    Does your CSTRING have an extra trailing newline by any chance? Please edit your question to include the output of echo "$CSTRING" | xxd (being sure to include the quotes) – steeldriver May 17 at 23:20
  • Looks like it might be a preceding newline...? Updated Question via edit. Thank you. – Ken Osborn May 17 at 23:25
  • Yes, that would do it also – steeldriver May 17 at 23:27
  • Thank you very much for your help!!! Is there some way I can give you credit when marking this as answered...? (I'm new here). – Ken Osborn May 17 at 23:31
  • Thanks - I have added a brief answer below in case someone else finds it useful – steeldriver May 17 at 23:42
1

It turns out that CSTRING contains a literal newline.

By enabling shell debugging we can see what sed sees:

$ set -x
$ sed "s/<ADD DEVICE CONNECTION STRING HERE>/$CSTRING/g" config.yaml
+ sed 's/<ADD DEVICE CONNECTION STRING HERE>/
HostName=PulseAzure-BetterTogetherDemo.azure-devices.net;DeviceId=ubuntu1804-ko-001;SharedAccessKey=xdWDu2gnzsfsdfdsfds=/g' config.yaml

and it's the sed 's/<ADD DEVICE CONNECTION STRING HERE>/ that is causing the

sed: -e expression #1, char 38: unterminated `s' command

error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.