Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing two unsorted lists in linux, listing the unique in the second file

I have 2 files with a list of numbers (telephone numbers).

I'm looking for a method of listing the numbers in the second file that is not present in the first file.

I've tried the various methods with:

comm (getting some weird sorting errors) fgrep -v -x -f second-file.txt first-file.txt (unsure of the result, there should be more) 
like image 730
mvrasmussen Avatar asked Jun 19 '12 11:06

mvrasmussen


1 Answers

grep -Fxv -f first-file.txt second-file.txt 

Basically looks for all lines in second-file.txt which don't match any line in first-file.txt. Might be slow if the files are large.

Also, once you sort the files (Use sort -n if they are numeric), then comm should also have worked. What error does it give? Try this:

comm -23 second-file-sorted.txt first-file-sorted.txt 
like image 161
Hari Menon Avatar answered Sep 20 '22 14:09

Hari Menon