所以想比较下下python,sed与grep:
测试文本:20w行,21M大
python普通正则匹配:
复制代码
代码如下:#!/usr/bin/python3
import re
f=open('/tmp/test.txt')
for line in f:
match=re.findall('^This.*want',line)
if match != []:
print(match)
结果:

复制代码
代码如下:#!/usr/bin/python3
import re
f=open('/tmp/test.txt')
re_obj=re.compile('^This.*want')
for line in f:
match=re_obj.findall(line)
if match != []:
print(match)
结果快了1倍:

试试sed:

最后试试grep:

果然grep是查找最专业的!




![RedHat服务器上[Errno 5] OSError: [Errno 2]的解决方法](https://img.pc-daily.com/uploads/allimg/4752/11135115c-0-lp.png)

