【问题标题】:Run fgrep multicore mac os x运行 fgrep 多核 mac os x
【发布时间】:2015-02-12 12:57:55
【问题描述】:

我在我的 8 核 Mac OS X 上运行这个命令:

for i in $(cat file1);do grep "$i" file2; done > output.txt

我的文件 2 有 900 万行,所以需要很多时间。

是否可以使用所有内核更快地完成这项工作?

【问题讨论】:

  • 请尝试在 UNIX & LinuxAsk Different 上提问。
  • 摆脱循环并使用grep -f file1 file2 > output.txt会更有效。
  • 但我想以与 file1 相同的顺序获得结果。我的脚本它可以工作,但它太慢了

标签: macos grep multicore


【解决方案1】:

你可以试试这个awk

awk 'FNR==NR {a[$0];next} {for (i in a) if ($0~i) print}' file1 file2  > output.txt

但我猜Paul R 发布的grep 会更快。

grep -f file1 file2 > output.txt 

【讨论】:

  • 我知道这更快,但我希望输出与 file1 的顺序相同,为此我使用了我的脚本
【解决方案2】:

基于http://www.gnu.org/software/parallel/man.html#EXAMPLE:-Grepping-n-lines-for-m-regular-expressions

parallel -k parallel --pipepart --block 100M -a file2 -k grep {} :::: file1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多