gpt4 book ai didi

command-line - 如何显示共同点(反向差异)?

转载 作者:行者123 更新时间:2023-12-03 04:18:02 25 4
gpt4 key购买 nike

我有一系列文本文件,我想知道它们之间的共同行而不是不同行。命令行 Unix 或 Windows 都可以。

文件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)

文件:

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

因此,鉴于上面这两个文件,所需实用程序的输出将类似于 file1:line_number, file2:line_number == 匹配文本 (只是一个建议;我真的不在乎语法是什么):

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

最佳答案

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

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 之前对文件进行排序非常重要。

关于command-line - 如何显示共同点(反向差异)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/746458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com