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.
diffinv is the inverse of the diff function.
Use comm -12 file1 file2 to get common lines in both files. You may also needs your file to be sorted to comm to work as expected. Or using grep command you need to add -x option to match the whole line as a matching pattern. The F option is telling grep that match pattern as a string not a regex match.
Here is a solution that WILL NOT change the order of the lines:
fgrep -x -f file1 file2
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With