我有这份文件。
如果我用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终端中获得所请求的内容?当显示ASCII (DOS-charset)时,在总指挥官中使用什么编码?还是iconv中的一个bug?
发布于 2022-04-21 10:41:01
它不是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.$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做得很好
发布于 2022-04-21 10:43:16
ASCII是一种7位编码.,您的文件以一串字节( 0xdb )开始,这是一个8位的值.
如果它是(部分)图形化的,它可能是8位DOS代码页之一。我试着使用CP850和CP437,而后者似乎给出了一幅合理的画面。
有道理,因为页437是最初的IBM代码页.和拉850拉丁文-1。前者具有更多的绘图字符,比如组合的单行/双线,以及垂直减半的框,这两个字符在CP850中都被一些重音字母所取代。
$ $ iconv -f cp437 -t utf8 < input.txt | head -10
█████████████████████████████████▀▀▀▀▀▀▀▀██▀▀▀▀▀▀▀▀████████████████████████████
██████████████████████▀▀▀▀ ▄▄▄▄ ▄█▓▓▓▓█▌ ▄█▓▓▓▓█▄▄ ▀█████████████████████████
███████████████▀▀ ▄▄▄▄▄▓█▓▓▓▒▒▐▌▐▓▓▒▒▒▒▓█▌▐█▓▒▒▒▒▒▒▀█ ▄▄▄▄ ▀██████████████████
██████▀▀▀▀▀▀ ▄▄▄▀█▓██▓█▓▒▒▒▒░░░█ █▒░░░░▒▌░▓█▄░░░░░░▄█ █▓▒▒▀█▄ ▀▀▀██████████████
██▀ ▄▄▄▓▒▄ █▓▓██▌▐▒█▓▒██░░░░░░▄█░▀█▄▄▄▄▀░ ░ ▀▀██▒▓▓█▌▐▌▒▒░░▓█▌▐█▄▄▄▄▄ ▀▀███████
██ ███████ █▒▒▓▀▄▐░▓▒░█▀▄▄▄▀▀▀▀ ▀▀▀▀▀ ▐▓▓▓▒░▓█ █▓▒░░░▒▒▓▄ ▀█████
██ ▓▓▓████▌▐░░▄▀▄ ▄▄▀▀ ░░ ░░░░ ▀▀▀█▒█ ▐█▄░░░░░░▒▓█ ▄▄ ██
██ ▒▒▒▓████ ▓▄▀▀ ▀ ░ ░ ░░█▓▄▌ ▄░░ ░░██░░████░░ ░ ▀▀██▄▄▒▓█▌▐█▀ ██
██ ░░░▒▓█▀ ░▒░ ░░░▒▓▒▓█ ▐▓▒░░▒▒▓█░░▓▓█▓░░█▓█▓ ▐▓░ ▀▀▀█▓ ██░ ██
██ ▄▄▀▀ ▄▄▄█▓░ ░▒▓░ ░▒▓▒▓▒░▒▓ ▓▒▓▒░▓▓▒▓▒▒▒▒▓▒▒▒▓▒▓▒▌ ▀▄▄█▓███ ▀█ (在SE上,这看起来不太好,但你明白了。)
https://unix.stackexchange.com/questions/699845
复制相似问题