iconvはASCIIから変換できません。

iconvはASCIIから変換できません。

このファイルがあります。

トータルコマンダーで開いてF3押すとS正確な内容が出ます。

私はbashでも同じことをしようとしますiconv

iconv -f ASCII -t UTF8 input.txt

しかし、私はこれを得ます:

iconv: illegal input sequence at position 0

私がCP850またはで行う場合CP852

iconv -f CP850 -t UTF8 input.txt

iconv -f CP852 -t UTF8 input.txt

出力に不要な文字が含まれます。

̦ŮŢŮ

Linux端末でもリクエストされたコンテンツをどのように取得できますか? Total Commanderはディスプレイにどのエンコーディングを使用しますかASCII (DOS-charset)?それともバグですかiconv

ベストアンサー1

ASCIIではないため、ファイルをASCIIから別のものに変換することはできません。わずかな調査の後、エンコーディングはCP437「良い」視覚表現を提供するようです。後で参照できるようにこれを決定する方法は次のとおりです。

# Workspace
mkdir picture
cd picture

# Get the file
curl http://tiborzsitva.szm.com/ascii/input.txt >x
file x
x: ISO-8859 text, with CRLF line terminators

# Try and convert with every possible conversion
for e in $(iconv -l | awk '{print $1}')
do
    iconv -f "$e" -t utf8 <x >"x.$e" 2>"x.$e.error"
done

# Delete the failed conversion attempts (those with error reports)
for f in x.*
do
    [ -s "$f.error" ] && rm -f "$f"
    rm -f "$f.error"
done

# Link identical files together
for f in x.*
do
    c=$(cksum <"$f")
    cf="x.cksum.${c// /_}"
    [ -f "$cf" ] && ln -f "$cf" "$f" || ln -f "$f" "$cf"
done
rm -f x.cksum.*

# See what each one looks like
ls -l x.*
less x.*

# The first one (437) looks good so look for a nice encoding name
iconv -l | grep -w 437
437 CP437 IBM437 CSPC8CODEPAGE437

CP437やってみるといいと思う

おすすめ記事