How to do the opposite of diff?
19,793
Solution 1
Here is a solution that WILL NOT change the order of the lines:
fgrep -x -f file1 file2
Solution 2
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
Author by
Justin Yoder
Updated on June 19, 2022Comments
-
Justin Yoder almost 2 years
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.
-
Arthur almost 4 yearsThis is not a reverse diff, but may be useful nonetheless. It prints the lines in
file2
that exactly match some line infile1
.fgrep
searches for fixed string matches-f
uses file1 as a list of grep search patterns-x
print only lines matched entirely