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

前端 未结 5 1926
既然无缘
既然无缘 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 16:15

    Here are a few options:

    1) Prefix your grep command with LC_ALL=C to use the C locale instead of UTF-8.

    2) Use fgrep because you're searching for a fixed string, not a regular expression.

    3) Remove the -i option, if you don't need it.

    So your command becomes:

    LC_ALL=C fgrep -A 5 -B 5 'db_pd.Clients' eightygigsfile.sql
    

    It will also be faster if you copy your file to RAM disk.

提交回复
热议问题