Cannot convert � to readable string with iconv

假装没事ソ 提交于 2019-12-11 19:09:21

问题


I have a large text file with a iso-8859-1 encoding which I obtain from:

file -i file.txt

When I cat a file to see the data, there will be a �� instead of a Thai string. At first, I think that I can just use iconv in linux to convert the encoding format to other type which I found iso-8859-11 format that can read Thai string and think that it will work. Something like this:

iconv -f iso-8859-1 -t iso-8859-11 file.txt > output.txt

But instead, I got this error:

iconv: illegal input sequence at position 1169

which is the location that has ��. I tried with //TRANSLIT but still got an unreadable character.

Are there any way that I can convert this text file to read Thai string? I know that I can just open a file with some text editor and save as a encoding format that I want but I have too many files and each file is nearly a gigabyte size. I think that iconv can helpe me convert every file without manually convert each one.

Ps. I have try open with Python:

with open('file.txt','r+', encoding='iso-8859-11') as f:
   print(f.read())

which can read Thai character perfectly but I need to convert a large and many files here so iconv is needed.

来源:https://stackoverflow.com/questions/56937706/cannot-convert-to-readable-string-with-iconv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!