Grepping 一个巨大的文件 (80GB) 有什么方法可以加快速度? [英] Grepping a huge file (80GB) any way to speed it up?

查看:19
本文介绍了Grepping 一个巨大的文件 (80GB) 有什么方法可以加快速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 grep -i -A 5 -B 5 'db_pd.Clients'  eightygigsfile.sql

这已经在相当强大的 linux 服务器上运行了一个小时,否则不会超载.有什么替代 grep 的吗?关于我的语法的任何可以改进的地方,(egrep、fgrep 更好?)

This has been running for an hour on a fairly powerful linux server which is otherwise not overloaded. Any alternative to grep? Anything about my syntax that can be improved, (egrep,fgrep better?)

该文件实际上位于一个目录中,该目录与另一台服务器的挂载共享,但实际磁盘空间是本地的,因此应该没有任何区别?

The file is actually in a directory which is shared with a mount to another server but the actual diskspace is local so that shouldn't make any difference?

grep 占用了高达 93% 的 CPU

the grep is grabbing up to 93% CPU

推荐答案

这里有几个选项:

1) 在 grep 命令前加上 LC_ALL=C 以使用 C 语言环境而不是 UTF-8.

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

2) 使用 fgrep 因为您正在搜索固定字符串,而不是正则表达式.

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

3) 删除 -i 选项,如果你不需要它.

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

所以你的命令变成:

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

如果您将文件复制到 RAM 磁盘,速度也会更快.

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

这篇关于Grepping 一个巨大的文件 (80GB) 有什么方法可以加快速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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