How can I convert Cyrillic stored as LATIN1 ( sql ) to true UTF8 Cyrillic with iconv?

让人想犯罪 __ 提交于 2019-12-12 08:13:54

问题


I have a SQL dump file consisting of incorrectly stored Cyrillic Russian ( WINDOWS-1251 ) text, example Èðàíñêèå which should properly be displayed as Иранские.

In the past I have successfully converted the sql file but memory fails in what I did and in what order.

Logically it would make sense that since it's stored in LATIN1 I would convert from LATIN1 to WINDOWS-1251 and then from WINDOWS-1251 to UTF-8//TRANSLIT or something like that.

So far I've tried:

1.

iconv -f WINDOWS-1251 -t UTF-8//TRANSLIT -o new.sql snippet.sql

Output:

Èðàíñêèå ( Not what I want )

2.

iconv -f LATIN1 -t UTF-8//TRANSLIT -o new.sql snippet.sql 

Output:

Ã<88>ðàíñêèå ( Not what I want either )

Notes

  • It's possible that I might have converted once and then twice to get my desired result, but I'm pretty sure that on the last step I converted from WINDOWS-1251 to UTF-8//TRANSLIT as that was written down in my notes.

  • One other note is that I'm viewing Èðàíñêèå in the SQL file when the file encoding is utf8 ( native in vim ). If I do set enc=latin1 in vim then I see ~Hð| íñêèå as if that doesn't make it more confusing.


回答1:


iconv -f utf-8 -t latin1 < in.sql | iconv -f cp1251 -t utf-8 > out.sql


来源:https://stackoverflow.com/questions/2396376/how-can-i-convert-cyrillic-stored-as-latin1-sql-to-true-utf8-cyrillic-with-i

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