아래 코드를 사용하여 '\u00c0'과 같은 문자를 'À'와 같은 유니코드 형식으로 변환합니다.
unicode(){ sed -i 's/\\\u00c0/À/g' $1;sed -i 's/\\\u00c1/Á/g' $1;sed -i 's/\\\u00c2/Â/g' $1;sed -i 's/\\\u00c3/Ã/g' $1;sed -i 's/\\\u00c4/Ä/g' $1;sed -i 's/\\\u00c5/Å/g' $1;sed -i 's/\\\u00c6/Æ/g' $1;sed -i 's/\\\u00c7/Ç/g' $1;sed -i 's/\\\u00c8/È/g' $1;sed -i 's/\\\u00c9/É/g' $1;sed -i 's/\\\u00ca/Ê/g' $1;sed -i 's/\\\u00cb/Ë/g' $1;sed -i 's/\\\u00cc/Ì/g' $1;sed -i 's/\\\u00cd/Í/g' $1;sed -i 's/\\\u00ce/Î/g' $1;sed -i 's/\\\u00cf/Ï/g' $1;sed -i 's/\\\u00d0/Ð/g' $1;sed -i 's/\\\u00d1/Ñ/g' $1;sed -i 's/\\\u00d2/Ò/g' $1;sed -i 's/\\\u00d3/Ó/g' $1;sed -i 's/\\\u00d4/Ô/g' $1;sed -i 's/\\\u00d5/Õ/g' $1;sed -i 's/\\\u00d6/Ö/g' $1;sed -i 's/\\\u00d7/×/g' $1;sed -i 's/\\\u00d8/Ø/g' $1;sed -i 's/\\\u00d9/Ù/g' $1;sed -i 's/\\\u00da/Ú/g' $1;sed -i 's/\\\u00db/Û/g' $1;sed -i 's/\\\u00dc/Ü/g' $1;sed -i 's/\\\u00dd/Ý/g' $1;sed -i 's/\\\u00de/Þ/g' $1;sed -i 's/\\\u00df/ß/g' $1;sed -i 's/\\\u00e0/à/g' $1;sed -i 's/\\\u00e1/á/g' $1;sed -i 's/\\\u00e2/â/g' $1;sed -i 's/\\\u00e3/ã/g' $1;sed -i 's/\\\u00e4/ä/g' $1;sed -i 's/\\\u00e5/å/g' $1;sed -i 's/\\\u00e6/æ/g' $1;sed -i 's/\\\u00e7/ç/g' $1;sed -i 's/\\\u00e8/è/g' $1;sed -i 's/\\\u00e9/é/g' $1;sed -i 's/\\\u00ea/ê/g' $1;sed -i 's/\\\u00eb/ë/g' $1;sed -i 's/\\\u00ec/ì/g' $1;sed -i 's/\\\u00ed/í/g' $1;sed -i 's/\\\u00ee/î/g' $1;sed -i 's/\\\u00ef/ï/g' $1;sed -i 's/\\\u00f0/ð/g' $1;sed -i 's/\\\u00f1/ñ/g' $1;sed -i 's/\\\u00f2/ò/g' $1;sed -i 's/\\\u00f3/ó/g' $1;sed -i 's/\\\u00f4/ô/g' $1;sed -i 's/\\\u00f5/õ/g' $1;sed -i 's/\\\u00f6/ö/g' $1;sed -i 's/\\\u00f7/÷/g' $1;sed -i 's/\\\u00f8/ø/g' $1;sed -i 's/\\\u00f9/ù/g' $1;sed -i 's/\\\u00fa/ú/g' $1;sed -i 's/\\\u00fb/û/g' $1;sed -i 's/\\\u00fc/ü/g' $1;sed -i 's/\\\u00fd/ý/g' $1;sed -i 's/\\\u00fe/þ/g' $1;sed -i 's/\\\u00ff/ÿ/g' $1; }
그런 다음 유니코드로 변환하는 데 사용합니다 unicode file.txt
.
예를 들어, original_text라는 파일이 있고 여기에 \u00d8rsted와 같은 문자열이 있는 경우 run을 실행하면 unicode original_text
해당 문자열이 Ørsted
.
이것은 매우 잘 작동하지만 코드가 매우 잘못된 것 같고 실제로는 약간 보기에도 좋지 않습니다.
이러한 변환을 수행하는 더 좋은 방법이 있는지 궁금합니다(쉘에서 또는 이러한 문자를 변환하는 unix 명령에서도).
답변1
ascii2uni
~에서uni2ascii그렇게 할 수 있습니다.
$ ./ascii2uni -q -a U <<< '\u00d8rsted'
Ørsted