gpt4 book ai didi

python - 如何从python中的日志中提取 key

转载 作者:行者123 更新时间:2023-12-02 20:09:25 24 4
gpt4 key购买 nike

我编写了python代码,以便从日志中提取 key 。使用相同的日志,它在一台机器上运行良好。但是当我在hadoop中运行它时,它失败了。我猜使用regex时有一些错误.谁能给我点意见?是regex不支持hadoop?

此 python 代码旨在提取 qryrc ,并计算 rc 的值,然后打印为qry query_count rc_count .当在hadoop中运行它时,它会报告
java.lang.RuntimeException: PipeMapRed.waitOutputThreads(): subprocess failed with code 1 .

我搜索谷歌,您的映射器代码中可能存在一些错误。那么我该如何解决呢?

像这样的日志格式,

NOTICE: 01-03 23:57:23: [a.cpp][b][222] show_ver=11 sid=ae1d esid=6WVj uid=D1 a=20 qry=cars qid0=293 loc_src=4 phn=0 mid=0 wvar=c op=0 qry_src=0 op_type=1 src=110|120|111 at=60942 rc=3|1|1 discount=20 indv_type=0 rep_query=



我的python代码就是这样
import sys
import re

for line in sys.stdin:
count_result = 0
line = line.strip()
match=re.search('.*qry=(.*?)qid0.*rc=(.*?)discount',line).groups()
if (len(match)<2):
continue
counts_tmp = match[1].strip()
counts=counts_tmp.split('|')
for count in counts:
if count.isdigit():
count_result += int(count)
key_tmp = match[0].strip()
if key_tmp.strip():
key = key_tmp.split('\t')
key = ' '.join(key)
print '%s\t%s\t%s' %(key,1,count_result)

最佳答案

最有可能的是您的正则表达式捕获的内容超出了您的预期。我建议将其拆分为一些更简单的部分,例如:

(?<= qry=).*(?= quid0)


(?<= rc=).*(?= discount)

关于python - 如何从python中的日志中提取 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18394844/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com