0

Using the command line utility sed stream editor, how can I replace the following string of regular and special characters ' with a single quote '

For example, I want to replace ' with a single quote ' from the below sentences:

FROM:

Nicholas Latifi: \'We didn\'t get through all the laps we wanted to\' in Mexico City Friday practice
Despite \'strong race pace\' in FP1, gearbox issues hampered George Russell\'s Mexican GP Friday practice

TO:

Nicholas Latifi: 'We didn't get through all the laps we wanted to' in Mexico City Friday practice
Despite 'strong race pace' in FP1, gearbox issues hampered George Russell's Mexican GP Friday practice
1
  • What have you tried so far, how does it not work?
    – nohillside
    Commented Nov 6, 2021 at 14:16

1 Answer 1

3

It seems that you also want to strip away the semicolon, too: Hence:

sed -e "s/'/'/g" file > file.new

or without output redirection, modifying in-place:

sed -ie "s/'/'/g" file

The 'g' modifier signals that a global substitution (i.e. all occurrences in each line) is desired.

If you have a string to filter this will look like:

echo "hello'world"|sed -e "s/'/'/g"
hello'world

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .