针对大文件 grep 大列表 [英] grep a large list against a large file

查看:20
本文介绍了针对大文件 grep 大列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试针对更大的 csv 文件(3.000.000 行)grep 一个大的 id 列表(~5000).

I am currently trying to grep a large list of ids (~5000) against an even larger csv file (3.000.000 lines).

我想要包含 id 文件中的 id 的所有 csv 行.

I want all the csv lines, that contain an id from the id file.

我天真的方法是:

cat the_ids.txt | while read line
do
  cat huge.csv | grep $line >> output_file
done

但这需要永远!

有没有更有效的方法来解决这个问题?

Are there more efficient approaches to this problem?

推荐答案

尝试

grep -f the_ids.txt huge.csv

此外,由于您的模式似乎是固定字符串,因此提供 -F 选项可能会加快 grep 的速度.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆