如何计算Linux上两个文件之间的差异? [英] How to count differences between two files on linux?

查看:28
本文介绍了如何计算Linux上两个文件之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要处理大文件并且必须找到两者之间的差异.而且我不需要不同的位,而是需要不同的数量.

I need to work with large files and must find differences between two. And I don't need the different bits, but the number of differences.

找到我想出的不同行的数量

To find the number of different rows I come up with

diff --suppress-common-lines --speed-large-files -y File1 File2 | wc -l

它有效,但有更好的方法吗?

And it works, but is there a better way to do it?

以及如何计算差异的确切数量(使用标准工具,如 bash、diff、awk、sed 一些旧版本的 perl)?

And how to count the exact number of differences (with standard tools like bash, diff, awk, sed some old version of perl)?

推荐答案

diff -U 0 file1 file2 | grep -v ^@ | wc -l

diff 列表顶部的两个文件名减去 2.统一格式可能比并排格式快一点.

That minus 2 for the two file names at the top of the diff listing. Unified format is probably a bit faster than side-by-side format.

这篇关于如何计算Linux上两个文件之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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