grep -vf 对于大文件太慢 [英] grep -vf too slow with large files
本文介绍了grep -vf 对于大文件太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用存储在 filter.txt 文件中的模式从 data.txt 中过滤数据.如下图,
I am trying filter data from data.txt using patterns stored in a file filter.txt. Like below,
grep -v -f filter.txt data.txt > op.txt
对于 filter.txt 中的 30-40K 行和 data.txt 中的 ~300K 行,此 grep 需要超过 10-15 分钟.
This grep takes more than 10-15 minutes for 30-40K lines in filter.txt and ~300K lines in data.txt.
有什么办法可以加快速度吗?
Is there any way to speed up this?
数据.txt
data1
data2
data3
过滤器.txt
data1
op.txt
data2
data3
这适用于 codeforester 提供的解决方案,但在 filter.txt 为空时失败.
This works with solution provided by codeforester but fails when filter.txt is empty.
推荐答案
基于 Inian's 解决方案中的 相关发布后,此 awk
命令应该可以解决您的问题:
Based on Inian's solution in the related post, this awk
command should solve your issue:
awk 'FNR==NR {hash[$0]; next} !($0 in hash)' filter.txt data.txt > op.txt
这篇关于grep -vf 对于大文件太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文