How to do the opposite of diff? [duplicate]

2019-03-12 14:55发布

Possible Duplicate:
how to show lines in common (reverse diff)?

Is there a command to do the opposite of diff? I want to compare two files if the same thing exists in both create a list of them. i am trying to figure out what entry's exist in both files.

标签: linux shell diff
2条回答
地球回转人心会变
2楼-- · 2019-03-12 15:11

Use the join command:

join a.txt b.txt

assuming the files are sorted; if not:

sort a.txt > sorted_a.txt; sort b.txt > sorted_b.txt; join sorted_a.txt sorted_b.txt
查看更多
疯言疯语
3楼-- · 2019-03-12 15:13

Here is a solution that WILL NOT change the order of the lines:

fgrep -x -f file1 file2
查看更多
登录 后发表回答