Grepping 一个巨大的文件 (80GB) 有什么方法可以加快速度?

编程入门 行业动态 更新时间:2024-10-11 23:27:05
本文介绍了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) 有什么方法可以加快速度?

本文发布于:2023-10-26 17:35:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530855.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么   速度   文件   方法   Grepping

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!