Alex Rivera | Logout

How to do the opposite of diff?

Asked 2011-12-20T19:51:27.397
22

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.

Edit
Report

1 Answer

12

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
answered 2011-12-20T20:00:39.850

Your Answer