Search code examples
linuxseddouble-quotes

How do I escape double quotes in sed?


Trying to figure out how to use a sed command to replace a value when the string i am searching for has double-quotes as part of the string.

I have a config file called ABC.conf that list out the release version like so; "ReleaseSequence": 1555

I want to use sed to change the release number to 2053

I have tried the following sed command;

sed -i 's:"ReleaseSequence":.*:"ReleaseSequence": 2053:' ABC.conf

I get the error message;

sed: -e expression #1, char 24: unknown option to `s'

I have tried to escape the doubel-quotes with [\"], '"""', and "" but sed doesn't like any of those.


Solution

  • The double quotes are not the problem here. You have used : as the separator although your data also contains literal colons. Use a different separator

    sed -i 's#"ReleaseSequence":.*#"ReleaseSequence": 2053#' ABC.conf
    

    or backslash-escape the literal colons.