Skip to content
Advertisement

unterminated `s’ command error – trying to remove extra double quote

I am trying to edit a single row in a text file, by removing an unnecessary double quote in front of the name, i.e. “THE DELEON FAMILY DE. After the change it should look like this: THE DELEON FAMILY DE.

Here is my code:

grep 'THE DELEON FAMILY DE' all_boros.txt | sed 's/"THE DELEON FAMILY DE/THE DELEON FAMILY DE'

This is the error I get:

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

Advertisement

Answer

You are missing a the last / in the substitution command:

s/"THE DELEON FAMILY DE/THE DELEON FAMILY DE/
#                                           ^ Here

And you don’t need grep at all and you don’t need to repeat the replacement:

sed 's/"(THE DELEON FAMILY DE)/1/' all_boros.txt

Dependent on your needs you might want to use the global modifier, this will make the substitution command match multiply times for each line:

sed 's/"(THE DELEON FAMILY DE)/1/g' all_boros.txt

And you can use -i to do in place edit:

sed -i.bak 's/"(THE DELEON FAMILY DE)/1/g' all_boros.txt
#   ^ this will make a backup called all_boros.txt.bak while modifying the
#     original file
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement