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

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

问题描述

我需要处理大文件,必须找到两者之间的差异。 < / p>

为了找到不同行的数量,我想出了

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

它可以工作,但是有更好的方法吗?



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

解决方案

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

diff 列表。统一格式可能比并列格式快一点。


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?

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

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天全站免登陆