我正在尝试提出一个正则表达式,以便我可以使用将Weblog导入Hive。我不是正则表达式专家,我在尝试使用不同元数据处理日志中的两种不同事务类型时遇到问题。
日志包含Request和Reply事务,我提出的正则表达式适用于Request事务,但是由于回复在数据中包含'Heartbeat'而在Reply上失败。 这些日志每天最多可包含两万或更多条目。
到目前为止我的正则表达式
(^[0-9]*) ([0-9]*) ([0-9]*) ([0-9]*) ([0-9]*) ([^ ]*) ([^ ]*) ([^ ]*) ([0-9]*) ([0-9]*) ([0-9]*) ([^ ]*)(?:[:]) ([0-9]+.[0-9]+(?:\ms)) ([^ ]*)(?:[:]) (.*)\n
预期结果:
博客示例:
请求交易:
示例数据
0 20140625095038864 20140625095038864 0000 006 00/0000/000 LSEMPPRD Nestra 000 000000 00 Request: fafe805e-614e-41dd-9b0f-8ec5fbc8c882
结构:
Version = 0
EventTime = 20140625095038864
LogTime = 20140625095038864
SequenceNumber = 0000
Level = 006
InternalArea = 00/0000/000
MachineName = LSEMPPRD
ApplicationName = Nestra
DiscardedMessageCount = 000 000000 00
TranType = Request:
SessionKey = fafe805e-614e-41dd-9b0f-8ec5fbc8c882
Message = <GetAccountInfo xmlns="http://tempuri.org/"><accountSession xmlns:b="http://schemas.datacontract.org/2004/07/ApplicationServices.DataContracts.Common" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><b:SessionKey>8c737876-fccb-4352-8d06-9f19ccb34fd6</b:SessionKey><b:SessionToken i:nil="true"></b:SessionToken></accountSession></GetAccountInfo>
回复交易:
示例数据
0 20140625095038615 20140625095038646 0000 006 00/0000/000 LSEMPPRD Nestra 000 000000 00 Reply: 296.4057ms d594891a-6d9c-4b5c-913a-9dc302277534:
结构:
Version = 0
EventTime = 20140625095038615
LogTime = 20140625095038646
SequenceNumber = 0000
Level = 006
InternalArea = 00/0000/000
MachineName = LSEMPPRD
ApplicationName = Nestra
DiscardedMessageCount = 000 000000 00
TranType = Reply:
Heartbeat = 296.4057ms
SessionKey = d594891a-6d9c-4b5c-913a-9dc302277534:
Message = <GetAccountInfo xmlns="http://tempuri.org/"><accountSession xmlns:b="http://schemas.datacontract.org/2004/07/ApplicationServices.DataContracts.Common" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><b:SessionKey>8c737876-fccb-4352-8d06-9f19ccb34fd6</b:SessionKey><b:SessionToken i:nil="true"></b:SessionToken></accountSession></GetAccountInfo>
答案 0 :(得分:0)
在这里找到答案:
注意:确保使用的空格。在使用
之前在rubular中测试正则表达式:
(^[0-9]*) ([0-9]*) ([0-9]*) ([0-9]*) ([0-9]*) ([^ ]*) ([^ ]*) ([^ ]*) ([0-9]*) ([0-9]*) ([0-9]*) ([^ ]*)(?:[:]) ([0-9]+.[0-9]+|)(?:ms |)([^ ]*)(?:[:])
数据:2行
0 20140625095038864 20140625095038864 0000 006 00/0000/000 LSEMPPRD Nestra 000 000000 00 Request: fafe805e-614e-41dd-9b0f-8ec5fbc8c882:
0 20140625095038615 20140625095038646 0000 006 00/0000/000 LSEMPPRD Nestra 000 000000 00 Reply: 296.4057ms d594891a-6d9c-4b5c-913a-9dc302277534:
正则表达式:(完成 - 同时处理邮件部分) - 只需添加结尾:(。* $)
(^[0-9]*) ([0-9]*) ([0-9]*) ([0-9]*) ([0-9]*) ([^ ]*) ([^ ]*) ([^ ]*) ([0-9]*) ([0-9]*) ([0-9]*) ([^ ]*)(?:[:]) ([0-9]+.[0-9]+|)(?:ms |)([^ ]*)(?:[:]) (.*$)
验证:rubular