在字符集之间转换文本文件的最快、最简单的工具或方法是什么?

具体来说,我需要从UTF-8转换为ISO-8859-15,反之亦然。

一切都可以:你最喜欢的脚本语言的一行程序,命令行工具或其他用于操作系统的实用程序,网站等等。

目前为止的最佳解决方案:

在 Linux/UNIX/OS X/cygwin 上:

Gnu iconv suggested by Troels Arvin is best used as a filter. It seems to be universally available. Example: $ iconv -f UTF-8 -t ISO-8859-15 in.txt > out.txt As pointed out by Ben, there is an online converter using iconv. recode (manual) suggested by Cheekysoft will convert one or several files in-place. Example: $ recode UTF8..ISO-8859-15 in.txt This one uses shorter aliases: $ recode utf8..l9 in.txt Recode also supports surfaces which can be used to convert between different line ending types and encodings: Convert newlines from LF (Unix) to CR-LF (DOS): $ recode ../CR-LF in.txt Base64 encode file: $ recode ../Base64 in.txt You can also combine them. Convert a Base64 encoded UTF8 file with Unix line endings to Base64 encoded Latin 1 file with Dos line endings: $ recode utf8/Base64..l1/CR-LF/Base64 file.txt

在Windows Powershell (Jay Bazuzi)上:

PS C:\> gc - zh utf8 in.txt | out - zh ascii out.txt

(但是没有ISO-8859-15支持;它说支持的字符集是unicode, utf7, utf8, utf32, ascii, bigendianunicode, default和oem。)

Edit

你是指iso-8859-1支持吗?使用"String"可以做到这一点,反之亦然

gc -en string in.txt | Out-File -en utf8 out.txt

注意:可能的枚举值是“Unknown, String, Unicode, Byte, BigEndianUnicode, UTF8, UTF7, Ascii”。

CsCvt - Kalytta的字符集转换器是另一个伟大的基于命令行的Windows转换工具。


当前回答

假设您不知道输入编码,并且仍然希望实现大部分转换的自动化,我总结了前面的答案,总结出这一行。

iconv -f $(chardetect input.text | awk '{print $2}') -t utf-8 -o output.text

其他回答

如“如何纠正文件的字符编码?”Synalyze它!可以让你在OS X上轻松转换ICU库支持的所有编码。

此外,您还可以显示从所有编码转换为Unicode的文件的一些字节,以便快速查看哪个字节适合您的文件。

尝试VIM

如果你有vim,你可以使用这个:

没有对每种编码进行测试。

最酷的部分是你不需要知道源编码

vim +"set nobomb | set fenc=utf8 | x" filename.txt

注意,这个命令直接修改文件


解释部分!

+: vim打开文件时直接输入命令。通常用于在特定行打开文件:vim +14 file.txt |:多个命令的分隔符(如;在bash中) set nobomb:没有utf-8 BOM set fenc=utf8:设置新的编码为utf-8 doc link x:保存并关闭文件 Filename.txt:文件的路径 :这里的报价是因为管道。(否则bash将使用它们作为bash管道)

尝试EncodingChecker

github上的编码检查器

文件编码检查器是一个GUI工具,允许您验证一个或多个文件的文本编码。该工具可以显示所有选定文件的编码,或者仅显示不具有指定编码的文件的编码。

文件编码检查程序需要。net 4或更高版本才能运行。

对于编码检测,文件编码检查器使用UtfUnknown字符集检测器库。没有字节顺序标记(BOM)的UTF-16文本文件可以通过启发式检测。

iconv (1)

iconv -f FROM-ENCODING -t TO-ENCODING file.txt

此外,在许多语言中都有基于图标的工具。

使用这个Python脚本:https://github.com/goerz/convert_encoding.py 适用于任何平台。需要Python 2.7。