Ich möchte ein ‚grep‘ nutzen zu können, oder ‚pcregrep -M‘ wie-Lösung, die eine Protokolldatei analysiert, die die folgenden Parameter passend für:Parsing ein mehrzeiliges variabler Länge Protokolldatei
- Jeder Protokolleintrag können mehrere Zeilen lang sein
- Erste Zeile des Protokolleintrag hat den Schlüssel, den ich für
- Jede Taste auf mehr als eine Zeile suchen möchten erscheint
So im Beispiel unten ich möchte zurückkehren jede Zeile, die h als KEY1 darauf und alle unterstützenden Zeilen darunter bis zur nächsten Log-Nachricht.
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
Ich habe versucht, wie etwas zu tun ist: '(. * \ N) KEY1 +'
pcregrep -M Logfile
aber definitiv nicht richtig funktioniert.
Was definiert das Ende eines Eintrags? Ist sichergestellt, dass die Zeilen innerhalb eines Eintrags nicht mit einer Ziffer beginnen, sondern eine Zeile, die einen neuen Eintrag definiert? –
Dies könnte einfacher sein, wenn Sie ein kleines Skript anstelle einer Regex verwenden. Irgendein Grund, das nicht zu tun? –