Reputation: 2519
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.
hari's
to hari s
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.
Upvotes: 39
Views: 112504
Reputation: 1621
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
Upvotes: 69
Reputation: 1
I had to replace "0x" string with "32'h" and resolved with:
sed 's/ 0x/ 32\x27h/'
Upvotes: -1
Reputation: 154
The -i should replace it in the file sed -i 's/“/"/g' filename.txt
if you want backups you can do sed -i.bak 's/“/"/g' filename.txt
Upvotes: 0
Reputation: 21
Here is based on my own experience.
Please notice on how I use special char '
vs "
after sed
This won't do (no output)
2521 #> echo 1'2'3'4'5 | sed 's/'/ /g'
>
>
>
but This would do
2520 #> echo 1'2'3'4'5 | sed "s/'/ /g"
12345
Upvotes: 1
Reputation: 1106
This will do what you want to
echo "hari's"| sed 's/\x27/ /g'
It will replace single quotes present anywhere in your file/text. Even if they are used for quoting they will be replaced with spaces. In that case(remove the quotes within a word not at word boundary) you can use the following:
echo "hari's"| sed -re 's/(\<.+)\x27(.+\>)/\1 \2/g'
HTH
Upvotes: 35
Reputation: 98118
Just go leave the single quote and put an escaped single quote:
sed 's/'\''/ /g' input
also possible with a variable:
quote=\'
sed "s/$quote/ /g" input
Upvotes: 16