How can I replace bullets (octal value: 225, hexadecimal value: 95) with spaces?
I tried with the following commands:
echo '•test' | tr '\225' ' '
echo '•test' | awk '{gsub(/\225/," ");print $0}'
echo '•test' | sed 's/\o225/ /g'
echo '•test' | LANG='' sed 's/\o225/ /g'
echo '•test' | sed 's/\x95/ /g'
The above commands does not work.
Let's look at why your current efforts are failing:
$ echo '•test' | hexdump -C
00000000 e2 80 a2 74 65 73 74 0a |...test.|
00000008
These bullets are actually three bytes -- e2 80 a2
, not a single 0x95
.
A corrected sed expression works fine:
echo '•test' | sed -e 's/•/ /g'
...or (using bash-extended syntax not available in /bin/sh
)...
echo '•test' | sed -e $'s@\xe2\x80\xa2@ @g'
...or (using bash-builtin replacement functionality):
s='•test' # original string in s
orig='•' # item to replace
new=' ' # thing to replace it with
s2=${s//"$orig"/$new} # result in s2
...or (using GNU sed extensions, per @anubhava)...
echo '•test' | sed 's@\xe2\x80\xa2@ @g'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With