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

前端 未结 4 1065
无人共我
无人共我 2021-01-29 22:36

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.

4条回答
  •  执念已碎
    2021-01-29 23:03

    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
    

提交回复
热议问题