在终端中查找两个文本文件之间的匹配

Mir*_*rna 5 mac terminal command-line

我有一个包含 1,755,972 行(一个值/行)的大 .txt 文件。我有另一个 .txt 文件,它有 1,400 行(一个值/行)。无论两个列表之间的顺序如何,我都想查看两者之间的匹配情况。

有什么建议?

输入1.txt

rs1
rs2
...
rsn
Run Code Online (Sandbox Code Playgroud)

输入2.txt

rs10
rs8
rs1
...
rsn
Run Code Online (Sandbox Code Playgroud)

har*_*ymc 3

要获取两个文本文件共有的行,无论它们在文件中的顺序如何,请执行以下操作:

sort file1.txt > sorted1.txt
sort file2.txt > sorted2.txt
comm -12 sorted1.txt sorted2.txt
Run Code Online (Sandbox Code Playgroud)

sort -u如果您只想比较唯一的行,请使用。