简体   繁体   English

AWK-当RS为正则表达式时使用RT,则为我提供下一个匹配项的RS,而不是当前的

[英]AWK - Using RT when RS is a regexp gives me the RS of the next match not the current

I am trying to use gawk to extract paragraphs from a log and it is working perfectly up to the point where I want to include the record separator it found. 我正在尝试使用gawk从日志中提取段落,并且在我要包括发现的记录分隔符的情况下,它工作得非常好。

This is the command: 这是命令:

gawk --re-interval 'BEGIN{RS="[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}.[0-9]{1,6} \\[[A-Z]*\\]";} /983a99f8-bec6-11e1-80dd-059a821d0b73/ {print $0}' full.log 

If I add in print RT, $0, it prints the RT of the next match not the current match. 如果我在打印RT中添加$ 0,它将打印下一个匹配项而不是当前匹配项的RT。

This is some sample text 这是一些示例文本

9:08:06.899627 [DEBUG] <0.30065.3>@agent:1565 Recs to loop through:  [{agent_state,"OpenAcdAgent43","Jeff",
                            undefined,wrapup,
                            {call,"983a99f8-bec6-11e1-80dd-059a821d0b73",
                                voice,
                                {"8501112234","MorganGrimes"},
                                "9201",<0.30392.3>,[],
                                {client,"8221314","DCF",[],1340629596,
                                    1340629596},
                                [creole_general],
                                <0.30398.3>,outband,inband,inbound,10},
                            1340629658,undefined,"Default",1340629658
9:08:06.899707 [INFO] <0.168.0>@cpx_monitor:649 Down message for reference #Ref<0.0.16.137225> of <0.30064.3> due to normal

What I want to be 9:08:06.899627 [DEBUG] able to do is prepend 9:08:06.899627 [DEBUG] to my match but RS takes that away. 我想要成为9:08:06.899627 [DEBUG]能够做的是将9:08:06.899627 [DEBUG]放在我的比赛前面,但RS取消了。 I get 9:08:06.899707 [INFO] instead. 我得到9:08:06.899707 [INFO]代替。

Thanks! 谢谢!

That's because a record separator comes at the end of a record. 这是因为记录分隔符位于记录的末尾 So 9:08:06.899627 [DEBUG] is the end of an empty record and 9:08:06.899707 [INFO] is the end of the record that matches your GUID regex. 因此9:08:06.899627 [DEBUG]是空记录的结尾,而9:08:06.899707 [INFO]是与GUID正则表达式匹配的记录的结尾。

You need to save the previous RT and output the saved one. 您需要保存前一个RT然后输出保存的RT

gawk --re-interval 'BEGIN{RS="[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}.[0-9]{1,6} \\[[A-Z]*\\]";} /983a99f8-bec6-11e1-80dd-059a821d0b73/ {print savedRT, $0} {savedRT = RT}' full.log 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM