Skip to content

Replacing strings with special characters in command line sed

I want to uncomment a line of a config file by replacing the line %% {some_string, []}, with {some_string, []} in the command line.

I have tried a few different formats using sed:

sed 's/%% {some_string, []},/{some_string, []}/' filename

sed "s/%% {some_string, []},/{some_string, []}/" filename

sed "s/'%% {some_string, []},'/'{some_string, []}'/" filename

sed 's/"%% {some_string, []},"/"{some_string, []}"/' filename

but every time have received the output sed: -e expression #1, char (some number): unterminated s' command

I am assuming it’s something to do with my formatting because of my special characters, but can’t seem to find any other posts with the same characters that could be causing the issue. I also cannot declare these strings as variables beforehand as I need this to run in the command line.



sed requires you to escape the square brackets.

sed 's/%% {some_string, []},/{some_string, []}/' filename
User contributions licensed under: CC BY-SA
9 People found this is helpful