如何显示公共线(反向diff)? [英] how to show lines in common (reverse diff)?

查看:181
本文介绍了如何显示公共线(反向diff)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列文本文件,我想知道共同的线,而不是它们之间不同的线。命令行unix或windows都没问题。

I have a series of text files for which I'd like to know the lines in common rather than the lines which are different between them. Command line unix or windows is fine.

foo:

linux-vdso.so.1 =>  (0x00007fffccffe000)
libvlc.so.2 => /usr/lib/libvlc.so.2 (0x00007f0dc4b0b000)
libvlccore.so.0 => /usr/lib/libvlccore.so.0 (0x00007f0dc483f000)
libc.so.6 => /lib/libc.so.6 (0x00007f0dc44cd000)

bar:

libkdeui.so.5 => /usr/lib/libkdeui.so.5 (0x00007f716ae22000)
libkio.so.5 => /usr/lib/libkio.so.5 (0x00007f716a96d000)
linux-vdso.so.1 =>  (0x00007fffccffe000)


$ b $ p

So, given these two files above the output of the desired utility would be akin to file1:line_number, file2:line_number == matching text (just a suggestion, I really don't care what the syntax is):

foo:1, bar:3 == linux-vdso.so.1 =>  (0x00007fffccffe000)

感谢。

推荐答案

在* nix上,您可以使用 comm 。这个问题的答案是:

On *nix, you can use comm. The answer to the question is:

comm -1 -2 file1.sorted file2.sorted 
# where file1 and file2 are sorted and piped into *.sorted

这里是 comm

comm [-1] [-2] [-3 ] file1 file2
-1 Suppress the output column of lines unique to file1.
-2 Suppress the output column of lines unique to file2.
-3 Suppress the output column of lines duplicated in file1 and file2. 

另请注意,在使用comm之前对文件进行排序很重要,如手册页中所述。

Also note that it is important to sort the files before using comm, as mentioned in the man pages.

这篇关于如何显示公共线(反向diff)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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