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

前端 未结 4 1059
无人共我
无人共我 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:06

    This should work

    comm -13 <(sort file1) <(sort file2)
    

    It seems sort -n (numeric) cannot work with comm, which uses sort (alphanumeric) internally

    f1.txt

    1
    2
    21
    50
    

    f2.txt

    1
    3
    21
    50
    

    21 should appear in third column

    #WRONG
    $ comm <(sort -n f1.txt) <(sort -n f2.txt)   
                    1
    2
    21
            3
            21
                    50
    
    #OK
    $ comm <(sort f1.txt) <(sort f2.txt)
                    1
    2
                    21
            3
                    50
    

提交回复
热议问题