我有 2 个包含数字列表(电话号码)的文件。
我正在寻找一种方法来列出第一个文件中不存在的第二个文件中的数字。
我尝试了各种方法:
comm (getting some weird sorting errors)
fgrep -v -x -f second-file.txt first-file.txt (unsure of the result, there should be more)
最佳答案
grep -Fxv -f first-file.txt second-file.txt
基本上查找 second-file.txt
中与 first-file.txt
中的任何行都不匹配的所有行。如果文件很大,可能会很慢。
此外,一旦您对文件进行了排序(如果它们是数字则使用 sort -n
),那么 comm
也应该可以工作。它给出了什么错误?试试这个:
comm -23 second-file-sorted.txt first-file-sorted.txt
https://stackoverflow.com/questions/11099894/