srihari srihari - 30 days ago 7
Bash Question

How do I replace single quotes with space 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.

Answer Source

Try to keep sed commands simple as much as possible or else you'll get confused of what you'd written after reading it later.

#!/bin/bash
sed "s/'/ /g" myfile.txt