Using iconv to convert from UTF-16LE to UTF-8

社会主义新天地 提交于 2019-12-03 04:30:31

问题


Hi I am trying to convert some log files from a Microsoft SQL server, but the files are encoded using UTf-16LE and iconv does not seem to be able to convert them.

I am doing:

iconv -f UTF-16LE -t UTF-8 <filename>

I also tried to delete any carriage returns from the end of the line if there are any, but that did not fix it either. If I save it using gedit that works, but this is not a viable solution since I have hundreds of those files.

EDIT: Please see the new answer for the missing option


回答1:


I forgot the -o switch!

The final command is :

iconv -f UTF-16LE -t UTF-8 <filename> -o <new-filename>



回答2:


The command you specified will output to stdout. You can either use the -o parameter, or redirect your output:

with -o:

iconv -f UTF-16LE -t UTF-8 infile -o outfile

with piping:

iconv -f UTF-16LE -t UTF-8 infile > outfile

Both will yield the desired result.

However some versions of iconv (v1 on macOS for example) do not support the -o parameter and you will see that the converted text is echoed to stdout. In that case, use the piping option.



来源:https://stackoverflow.com/questions/17287713/using-iconv-to-convert-from-utf-16le-to-utf-8

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