iconv 非法输入序列 - 为什么?

use*_*107 16 character-encoding text-processing unicode

在尝试将文本文件转换为其 ASCII 等效文件时,我收到错误消息iconv: illegal input sequence at position.

我使用的命令是 iconv -f UTF-8 -t ascii//TRANSLIT file

冒犯的字符是æ

文本文件本身存在于此处

为什么说是非法序列?输入字符是正确的 UTF-8 字符 (U+00E6)。

vin*_*c17 19

该文件以 ISO-8859-1 编码,而非 UTF-8:

$ hd 0606461.txt | grep -B1 '^0002c520'
0002c510  64 75 6d 20 66 65 72 69  65 6e 74 20 72 75 69 6e  |dum ferient ruin|
0002c520  e6 0d 0a 2d 2d 48 6f 72  61 63 65 2e 0d 0a 0d 0a  |...--Horace.....|
Run Code Online (Sandbox Code Playgroud)

并且单独的字节“e6”不是有效的 UTF-8 序列。

所以,使用iconv -f latin1 -t ascii//TRANSLIT file.


ste*_*ver 5

您链接的文件在 HTML 文档中似乎是 UTF-8

$ file 0606461.txt 
0606461.txt: HTML document, ASCII text, with CRLF line terminators
Run Code Online (Sandbox Code Playgroud)

如果您首先通过 HTML 到文本转换器运行它,例如

iconv -f UTF-8 -t ascii//TRANSLIT < <(html2text 0606461.txt)
Run Code Online (Sandbox Code Playgroud)

那么您似乎遇到问题的 UTF-8 片段似乎可以无误地音译,即

Si fractus illabatur orbis.
Impavidum ferient ruinæ
--Horace.
Run Code Online (Sandbox Code Playgroud)

变成

Si fractus illabatur orbis.
Impavidum ferient ruinae
--Horace.
Run Code Online (Sandbox Code Playgroud)

html2text实用程序可能未安装在您的系统上 - 如果您无法找到/安装它,还有其他转换器,包括 python 模块。