相关疑难解决方法(0)

文本处理 - Python与Perl性能

这是我的Perl和Python脚本,用于从大约21个日志文件进行一些简单的文本处理,每个大约300 KB到1 MB(最大)x重复5次(总共125个文件,由于日志重复5次).

Python代码(修改后使用编译re和使用的代码re.I)

#!/usr/bin/python

import re
import fileinput

exists_re = re.compile(r'^(.*?) INFO.*Such a record already exists', re.I)
location_re = re.compile(r'^AwbLocation (.*?) insert into', re.I)

for line in fileinput.input():
    fn = fileinput.filename()
    currline = line.rstrip()

    mprev = exists_re.search(currline)

    if(mprev):
        xlogtime = mprev.group(1)

    mcurr = location_re.search(currline)

    if(mcurr):
        print fn, xlogtime, mcurr.group(1)
Run Code Online (Sandbox Code Playgroud)

Perl代码

#!/usr/bin/perl

while (<>) {
    chomp;

    if (m/^(.*?) INFO.*Such a record already exists/i) {
        $xlogtime = $1;
    }

    if (m/^AwbLocation (.*?) insert into/i) …
Run Code Online (Sandbox Code Playgroud)

python regex perl performance text-processing

67
推荐指数
3
解决办法
3万
查看次数

标签 统计

performance ×1

perl ×1

python ×1

regex ×1

text-processing ×1