regex - Parsing a multiline variable-length log file -
I want to be able to use a 'grep' or 'pcregrep -m' solution that parse the log file
- There may be multiple rows in each log entry length
- The first line of the log entry is the key that I < Li> Every key appears on one more line
So in the example below, I would like to return each row to it on which there is a key on it and until next log message there are all the support lines below.
log file: 01 February 2010 - 10: 39: 01.755, Debu - KA1: Rendextx blah blah 2 t blaza t t bla 4f blah 5f blaza 6 bw 7 01 February 2010 - 10: 3 9: 01.757, Debug - Key 1: Somethngelse 01 Feb 2010 - 10: 39: 01.758, DEBUG - KEY2: randomtest This is a test 01 February 2010 - 10: 39: 01.760, Debug - Key 1: More logs here 01 February 2010 - 10: 39: 01.762, Debug - KEY1: eve and this other multi line log entry continues but no longer 01 Feb 2010 - 10:39: 01.763, debuts - KE2: Tess Test Test Test and Off of 2 Feb. 02, 2010 - 10: 39: 01.762, Debug - KA1: Key 1 is still going and going and going and going and going and going Is going and going and going and going and going well and being okay 01 Feb 2010 - 10:39: 01.762, DEBUG - KEY3: and so on and
The desired output of search for KEY1: 01 February 2010 - 10: 39: 01.755, Debu - KA1: Randomtext Blah Blah 2 T Blaise 3 Bl Blah 4f Blah 5f Blast 6 Bama 7 01 February 2010 - 10: 39: 01.757, Debug - KY 1: Somthangal 01 February 2010 - 10:39 01.760, DEBUG - KEY1: More logs here 01 February 2010 - 10:39: 01.762, Debu - Key 1: here And here another more logging log entry is going on but before 01 February 2010 - 10: 3: 01.762, DEBUG - KEY1: But key 1 is still going and going and going and going Going and going and going, going and going and going and going properly
I'm trying to do something like this Was:
pcregrep -M 'KEY1 (. * \ N) + 'logfile - but certainly does not work right.
if you are * on the nick, you can use the shell
#! / Bin / bash read -p "Enter key:" key awk -vkey = "$ key" '$ 0 ~ / debug / & amp; Amp; $ 0! ~ Key {f = 0} $ 0 ~ key {f = 1} f {print} 'file
output
$ cat file February 01, 2010 - 10: 39: 01.755, Debug - KA1: Rendect Blah Blah 2 T Blaise T Blaee 4f Blah FF 5 Blah 7 01 Feb 2010 - 10:39: 01.757, Debug - Kay 1: Somathhellel 01 February 2010 - 10 : 39: 01.758, debug - KEY2: randomtest This is an exam 01 February 2010 - 10: 39: 01.760, DEBU - KEY1: More logs here 01 February 2010 - 10:39: 01.762, DEBU - KEY1: Eve and here it is Another multi-line log entry is but February 1, 201 Not going to 0 before - 10: 39: 01.763, Debug - KE2: Testi ng test test test and off of 2 02 Feb 2010 - 10: 39: 01.762, Debug - Key 1: But key 1 still moves Is going and is going and going and going and going and going and going and going and going and going okay 01 Feb 2010 - 10:39: 01.762, debug - key 3 : And so on and enter $ ./shell.sh key: KEY1 01 February 2010 - 10: 39: 01.755, Debuts - KEY1: Randomtex Blah Blah TT Blah3 t blah4 f blah5 f blah6 Blah7 01 Feb 2010 - 10: 39: 01.757, Debug - KA1: Somathangles 01 Feb 2010 - 10:39: 01.760, Debu - Kay 1: More Login here 01 Feb 2010 - 10:39: 01.762, DEBUG - KEY1: Here On the eve this another multi-line log entry continues but 01 Feb 2010 - 10: 39: 01.762, not before debug - key 1: but Key 1 is still going and going and going and going Is going and going and going and going and going, going and going and going well enough
Comments
Post a Comment