Skip to content
Advertisement

How do I replace single quotes with another character in sed?

I have a flat file where I have multiple occurrences of strings that contains single quote, e.g. hari's and leader's.

I want to replace all occurrences of the single quote with space, i.e.

  • all occurences of hari's to hari s
  • all occurences of leader's to leader s

I tried

sed -e 's/"'"/ /g' myfile.txt

and

sed -e 's/"'"/" "/g' myfile.txt

but they are not giving me the expected result.

Advertisement

Answer

Try to keep sed commands simple as much as possible. Otherwise you’ll get confused of what you’d written reading it later.

#!/bin/bash
sed "s/'/ /g" myfile.txt
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement