对一个大文件grep一个大列表 [英] grep a large list against a large file
本文介绍了对一个大文件grep一个大列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在针对更大的csv文件(3.000.000行)尝试 grep
大量id(〜5000)列表。
我想要所有csv行,包含id文件中的一个id。
我的天真方法是:
cat the_ids.txt |而读行
做
猫huge.csv | grep $ line>> output_file
完成
但是这需要永远!
有没有更有效的方法解决这个问题? 试试
grep -f the_ids.txt huge.csv
<另外,由于你的模式似乎是固定字符串,提供 -F
选项可能会加速 grep
。
-F,--fixed-strings
将PATTERN解释为由
分隔的固定字符串列表换行符,其中任何一个都要匹配。 (-F由
POSIX指定)
I am currently trying to grep
a large list of ids (~5000) against an even larger csv file (3.000.000 lines).
I want all the csv lines, that contain an id from the id file.
My naive approach was:
cat the_ids.txt | while read line
do
cat huge.csv | grep $line >> output_file
done
But this takes forever!
Are there more efficient approaches to this problem?
解决方案
Try
grep -f the_ids.txt huge.csv
Additionally, since your patterns seem to be fixed strings, supplying the -F
option might speed up grep
.
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by
newlines, any of which is to be matched. (-F is specified by
POSIX.)
这篇关于对一个大文件grep一个大列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文