我希望能够利用“的grep”或“pcregrep -M”一样的解决方案,分析适合下列参数的日志文件:解析多可变长度的日志文件
- 每个日志条目长度可以是多行
- 日志条目的第一行,我想搜索
- 在一个以上的线上的每个键出现
所以下面我希望回到例子中的关键每一行h作为KEY1和它下面的所有支持行,直到下一条日志消息。
Log file: 01 Feb 2010 - 10:39:01.755, DEBUG - KEY1:randomtext blah blah2 T blah3 T blah4 F blah5 F blah6 blah7 01 Feb 2010 - 10:39:01.757, DEBUG - KEY1:somethngelse 01 Feb 2010 - 10:39:01.758, DEBUG - KEY2:randomtest this is a test 01 Feb 2010 - 10:39:01.760, DEBUG - KEY1:more logs here 01 Feb 2010 - 10:39:01.762, DEBUG - KEY1:eve more here this is another multiline log entry keeps on going but not as long as before 01 Feb 2010 - 10:39:01.763, DEBUG - KEY2:testing test test test end of key2 01 Feb 2010 - 10:39:01.762, DEBUG - KEY1:but key 1 is still going and going and going and going and going and going and going and going and going and going and going and going and going okay enough 01 Feb 2010 - 10:39:01.762, DEBUG - KEY3:and so on and on
Desired output of searching for KEY1: 01 Feb 2010 - 10:39:01.755, DEBUG - KEY1:randomtext blah blah2 T blah3 T blah4 F blah5 F blah6 blah7 01 Feb 2010 - 10:39:01.757, DEBUG - KEY1:somethngelse 01 Feb 2010 - 10:39:01.760, DEBUG - KEY1:more logs here 01 Feb 2010 - 10:39:01.762, DEBUG - KEY1:eve more here this is another multiline log entry keeps on going but not as long as before 01 Feb 2010 - 10:39:01.762, DEBUG - KEY1:but key 1 is still going and going and going and going and going and going and going and going and going and going and going and going and going okay enough
我试图做类似: '(。* \ n)的KEY1 +'
pcregrep -M日志文件
但绝对不工作的权利。
什么定义了条目的结尾?是否保证条目中的行不会以数字开头,但是定义新条目的行将会是? – 2010-02-02 06:00:47
使用小脚本而不是正则表达式可能更容易。任何理由不这样做? – 2010-02-02 06:02:43