我有一个巨大的xml文件,其示例数据如下:
因为可以看到有文字“GesellschaftfürBildverarbeitung”,它不符合UTF-8,因为我从xml验证器得到错误,错误如:
Import failed:
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
那么查询是如何在Linux环境中处理这个问题,将xml文件转换为UTF-8兼容格式?或者在bash中是否存在这样的方式,以便在首先创建xml时,我可以确保所有变量/字符串都以UTF-8兼容格式存储?
解决方法:
使用字符集转换工具:
iconv -f ISO-8859-1 -t UTF-8 filename.txt
00-0B-91 (hex) Aglaia Gesellschaft für Bildverarbeitung und Kommunikation m
000B91 (base 16) Aglaia Gesellschaft für Bildverarbeitung und Kommunikation m
Tiniusstr. 12-15
Berlin D-13089
GERMANY
似乎“ü”是获得mangeld的角色.
更新
当使用wget下载“oui.txt”时,我在文件中看到字符“ü”.如果您没有在下载中破坏某些内容.考虑使用以下其中一种:
> wget –header =’Accept-Charset:utf-8′
>尝试使用curl -o oui.txt代替
如果以上都不起作用,只需在您喜欢的浏览器中打开链接并执行“另存为”.在这种情况下,请在下面的脚本中注释wget行.
我成功使用以下脚本(更新BEGIN& END以获取有效的XML文件)
#!/bin/bash
wget http://standards.ieee.org/develop/regauth/oui/oui.txt
iconv -f iso-8859-15 -t utf-8 oui.txt > converted
awk 'BEGIN {
print "HTML-header"
}
/base 16/ {
printf("\n", $4)
read
desc = substr($0, index($0, $4))
printf("\n", $1, desc)
}
END {
print "HTML-footer"
}
' converted
希望这可以帮助!
标签:shell,unix,linux,unicode,utf-8
来源: https://codeday.me/bug/20190630/1338523.html