How to replace Unicode characters with ASCII

前端 未结 4 762
被撕碎了的回忆
被撕碎了的回忆 2021-02-15 18:35

I have the following command to replace Unicode characters with ASCII ones.

sed -i \'s/Ã/A/g\'

The problem is à isn\'t recognized

4条回答
  •  天涯浪人
    2021-02-15 19:01

    It is possible to use hex values in "sed".

    echo "Ã" | hexdump -C
    00000000  c3 83 0a                                          |...|
    00000003
    

    Ok, that character is two byte combination "c3 83". Let's replace it with single byte "A":

    echo "Ã" |sed 's/\xc3\x83/A/g'
    A
    

    Explanation: \x indicates for "sed" that a hex code follows.

提交回复
热议问题