iconv:使用BOM从Windows ANSI转换为UTF-8

问题描述 投票:29回答:4

我想使用iconv在Mac上转换文件。目标是从“ Windows ANSI”转到“如果Windows记事本使用UFT8,则保存的所有内容”。

这就是我想要的:

anders-johansen-privats-macbook-pro:test andersprivat$ 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 

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

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

如何获取物料清单?

unicode iconv
4个回答
43
投票

您可以通过首先将字节echo放入文件中来手动添加它:

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

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

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

注意>>,而不是>


1
投票

请注意,“ Windows ANSI”可能不是CP1252-由用户配置。


0
投票

对于UTF-8,不需要BOM。Windows记事本可以保存带有或不带有BOM的UTF-8。


-5
投票

我需要对方。 (将德语文本从UTF-8转换为ANSI)

所以我使用了命令:1. iconv -l(检查可用格式)2. iconv -f UTF8 -t MS-ANSI de.txt> output.txt

现在,如果我打开output.txt,它已经在ANSI中。工作完成。

© www.soinside.com 2019 - 2024. All rights reserved.