iconv:使用 BOM 从 Windows ANSI 转换为 UTF-8 [英] iconv: Converting from Windows ANSI to UTF-8 with BOM

查看:66
本文介绍了iconv:使用 BOM 从 Windows ANSI 转换为 UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 iconv 在我的 Mac 上转换文件.目标是从Windows ANSI"转变为任何 Windows 记事本保存的内容,如果您告诉它使用 UFT8".

I want to use iconv to convert files on my Mac. The goal is to go from "Windows ANSI" to "whatever Windows Notepad saves, if you tell it to use UFT8".

这就是我想要的:

$ file names.csv 
names.csv: UTF-8 Unicode (with BOM) text, with CRLF line terminators

这是我使用的:

$ iconv -f CP1252 -t UTF-8  names.csv > names.utf8.csv 

这就是我得到的(不是我想要的):

This is what I get (not what I want):

$ file names.utf8.csv 
names.utf8.csv: UTF-8 Unicode text, with CRLF line terminators

我如何获得 BOM?

推荐答案

您可以通过先echo将字节输入文件来手动添加:

You can add it manually by first echoing the bytes into the file:

echo -ne '\xEF\xBB\xBF' > names.utf8.csv

然后在最后连接您所需的信息:

and then concatenating your required information at the end:

iconv -f CP1252 -t UTF-8  names.csv >> names.utf8.csv

注意 >> 而不是 >.

这篇关于iconv:使用 BOM 从 Windows ANSI 转换为 UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆