如何使用 GNU diff 比较 utf-16 文件?
GNU diff 似乎不够智能,无法检测和处理 UTF-16 文件,这让我感到惊讶。 我是否缺少一个明显的命令行选项? 有好的选择吗?
GNU diff doesn't seem to be smart enough to detect and handle UTF-16 files, which surprises me. Am I missing an obvious command-line option? Is there a good alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
vimdiff
非常适合此目的。我在阅读这个 StackOverflow 答案。
vimdiff
works quite nicely for this purpose.I found it while reading this StackOverflow answer.
来自 GNU diff 文档:
我自己从来没有意识到这一点。
如果非自由、非命令行工具可以完成这项工作,看起来 Guiffy 可以胜任这项工作,但仍在寻找免费软件命令行工具:
http://www.guiffy.com/Diff-Tool.html
From the GNU diff documentation:
I never realized that myself.
It looks like Guiffy could to the job if a nonfree, non-command line tool will do the job, still looking for a freeware command line tool:
http://www.guiffy.com/Diff-Tool.html
安装支持 UTF-16 的
ripgrep
实用程序,然后运行:Install
ripgrep
utility which supports UTF-16, then run:使用重音符号或特殊字符时的格式错误补丁:
正确处理重音符号或特殊字符,无论比较的文件/目录是否位于 git 文件夹中。
Malforms patches when accent marks or special characters are used:
Correctly handles accent marks or special characters regardless of whether compared files/dirs are in a git folder.
您可以使用优秀的 chardet 在 python 中构建一些东西,然后将您的文件转换为 UTF-8 并将其发送到 GNU diff ?
http://chardet.feedparser.org/
You could maybe build something in python with the excellent chardet, then convert your files to UTF-8 and send this to GNU diff ?
http://chardet.feedparser.org/
在 Python 中,您可以使用 difflib.HtmlDiff 创建一个 HTML 表,该表显示两个行序列之间的差异,并且它似乎可以很好地处理 Unicode 字符串(当然,前提是您使用适当的编解码器读取和写入它们)。
In Python, you can use difflib.HtmlDiff to create an HTML table that shows the differences between two sequences of lines, and it seems to work fine with Unicode strings (provided, of course, you read and write them with the appropriate codecs).
Meld 是一个支持 UTF-16 的开源 diff 工具。 它是免费且开源的,并得到 GNOME 项目的支持。
Meld is an open source diff tool that supports UTF-16. It's free and open source, and supported by the GNOME project.