As 1nickt suggested, you might find it easier to break the problem down into steps rather than trying to do it in one go. First separate the date, then extract the message from the remainder. For example
poj#!/usr/bin/perl use strict; # month numbers my %mno = (jan=>1,feb=>2,mar=>3,apr=>4, may=>5, jun=>6, jul=>7,aug=>8,sep=>9,oct=>10,nov=>11,dec=>12); # define date formats my $df1 = qr[... ... \d{2} \d{2}:\d{2}:\d{2} 20\d\d]; my $df2 = qr[20\d{2}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}]; # process log while (<DATA>){ chomp; if (/^($df1|$df2)\s+(.*)/){ my ($date,$time) = format_date($1); my $msg = $2; my $severity; my $err; if ($msg =~ /(\S*info:.*)/){ $severity = 'INFO'; $err = $1; } if ($msg =~ /(\[INFORMATION\])\s+(.*)/){ $severity = 'INFO'; $err = $2; $err =~ s/^\[.*\] +//; # remove [AGENTEXEC 26816] } print "$date\t$time\t$severity\t$err\n"; } } # Mon Feb 20 09:31:25 2017 sub format_date { my $date = shift; my $time; if ($date =~/(...) (\d{2}) (\d{2}:\d{2}:\d{2}) (20\d\d)/){ $date = sprintf "%4d-%02d-%02d",$4,$mno{lc $1},$2; $time = $3; } if ($date =~/(.+)T(\d{2}:\d{2}:\d{2})/){ $date = $1; $time = $2; } return ($date,$time); } __DATA__ Mon Feb 20 09:31:25 2017 [INFORMATION] [AGENTEXEC 26816] Detected duri +ng program initialization: Version: 7.2.0160.0297 Win64 2017-02-20T09:30:53.177000 20848[30892] 0000000000000000 [DM_ +MQ_I_DAEMON_START]info: "Message queue daemon (tid : 27944, session +0102b20d80000456) is started sucessfully."
In reply to Re^5: DateTime::Format::Flexible; for Log Parse with multiple formatted lines
by poj
in thread DateTime::Format::Flexible; for Log Parse with multiple formatted lines
by TCLion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |