1

Python 正規表現を使用して、3 GB のログ ファイルからデータをタプルとして抽出しようとしています。

ログの形式は次のとおりです。

2012-11-22 08:57:25,232 [P:DEBUG] moteId=245 statusElem=1
2012-11-22 08:57:25,042 [P:DEBUG] parsed into Tuple_IsSync(isSync=1)
2012-11-22 08:57:26,128 [P:DEBUG] parsed into Tuple_ScheduleRow(row=9, slotOffset=9, type=6, shared=0, channelOffset=0, neighbor_type=0, neighbor_bodyH=0, neighbor_bodyL=0, backoffExponent=1, backoff=0, numRx=0, numTx=0, numTxACK=0, lastUsedAsn_4=0, lastUsedAsn_2_3=0, lastUsedAsn_0_1=0, next=7638)

タプルが欲しい:

(2012-11-22, 08:57:25,042, moteId=245, statusElem=1, isSync=1, numRx=0, numTx=0, numTxACK=0,)

一行で。

import re
import sys

files=open('/Users/s/Desktop/p.log','r')

match=re.findall(r'\w[\s*moteId\s(statusElem)(isSync)(numTxAck).*]+.\d+',files.read())
f=open('/Users/s/Desktop/w.txt','w')
f.writelines(match)
f.close()

私のコードは、探しているものを正確に抽出していません。助言がありますか?

4

1 に答える 1