Grepping a huge file (80GB) any way to speed it up?

前端 未结 5 1932
既然无缘
既然无缘 2020-11-29 15:52
 grep -i -A 5 -B 5 \'db_pd.Clients\'  eightygigsfile.sql

This has been running for an hour on a fairly powerful linux server which is otherwise not

5条回答
  •  天涯浪人
    2020-11-29 15:55

    If you have a multicore CPU, I would really recommend GNU parallel. To grep a big file in parallel use:

    < eightygigsfile.sql parallel --pipe grep -i -C 5 'db_pd.Clients'
    

    Depending on your disks and CPUs it may be faster to read larger blocks:

    < eightygigsfile.sql parallel --pipe --block 10M grep -i -C 5 'db_pd.Clients'
    

    It's not entirely clear from you question, but other options for grep include:

    • Dropping the -i flag.
    • Using the -F flag for a fixed string
    • Disabling NLS with LANG=C
    • Setting a max number of matches with the -m flag.

提交回复
热议问题