我每天收到一个文件,其中包含 10,000 条记录,其中 99% 位于最后一天的文件中。如何使用 macOS 命令行删除前一天文件中存在的较新文件中的行?
remove_duplicates newfile oldfile
这些文件如下所示:
"First Last"\t"email"\t"phone"\t"9 more columns..."
注意,我试过 this awk
solution ,但它没有输出任何东西,即使我确认了重复的行。
最佳答案
您可能会将 grep
与 -v
(反转匹配)和 -f
(文件)选项一起使用:
grep -v -f oldfile newfile > newstrip
它匹配 newfile 中所有不在 oldfile 中的行,并将它们保存到 newstrip。如果您对结果感到满意,以后可以轻松完成:
mv newstrip newfile
这将用 newstrip 覆盖 newfile(删除 newstrip)。
关于bash - 如何删除一个文件中存在于另一个文件中的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50361306/