in reply to Re^4: Parsing log file with regular-expression match nested brackets
in thread Parsing log file with regular-expression match nested brackets [RESOLVED]

Is this close to want you want ?

#!/usr/bin/perl use strict; use warnings; use Data::Dump 'pp'; my %hash = (); my $level = 0; my $key; while (<DATA>){ next unless /\S/; my ($proc,$data) = split ':\s+',$_,2; if ($level == 0){ $key = $proc; } else { push @{$hash{$key}},$data if (defined $data); } ++$level if /{/; --$level if /}/; } pp \%hash; __DATA__ [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Rx: UDT{ [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Rx: l +ine2: data [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Rx: l +ine3: data [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Rx: l +ine4: data [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Rx: l +ine5: data [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Rx: l +ine6: data [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Rx: l +ine7: data } [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Tx: UDT{ [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Tx: l +ine10: data [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Tx: l +ine11: data [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Tx: l +ine12: data [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Tx: l +ine13: data [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Tx: l +ine14: data [ 11] 25/2/2017-19:02:06.980 proces_name thanos-Tx: l +ine15: data }
poj
  • Comment on Re^5: Parsing log file with regular-expression match nested brackets
  • Download Code

Replies are listed 'Best First'.
Re^6: Parsing log file with regular-expression match nested brackets
by thanos1983 (Parson) on Feb 28, 2017 at 22:36 UTC

    Hello poj,

    Although the script works nicely I tested it with the complete log file and unfortunately it does not parse the file as I would expect the output to be.

    Sample of output:

    I need to work with the regex that I have at the beginning, this is the closest solution that I have got to my problem.

    Update: Inserting  <readmore> </readmore> tags to minimize space consumed.

    Thank you for your time and effort reading and replying to my question.

    Seeking for Perl wisdom...on the process of learning...not there...yet!