linux - 比较linux中两个未排序的列表,列出第二个文件中的唯一性

我有 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/

相关文章:

linux - 如何在 Linux Shell 脚本中检查组是否存在并添加是否不存在

linux - 一个 C hello world 的汇编输出的每一行是什么意思?

linux - 向 unix shell 变量添加换行符

regex - 你如何用 sed "debug"一个正则表达式?

c - 从命令行将参数传递给 C 程序

python - 如何在python中检索进程开始时间(或正常运行时间)

linux - 如何在 Linux 上安装 Node 二进制分发文件

c - 在 C 中检测 64 位编译

linux - 试运行 cron 条目

linux - PHP CURL 启用 Linux