You're most welcome, Ben328! Am glad it worked for you...
The following will capture all four fields from each record of your data set, so you can work with them as needed:
use strict;
use warnings;
{
local $/;
open my $fh, '<', 'logFile.txt' or die $!;
my $data = <$fh>;
while (
$data =~ /
(?=\[\d{4}) # Start record
\[(?<date>.+?)\]\s*
\[(?<active>.+?)\]\s*
ExecuteThread:\s*(?<executeThread>.+?)
INFO\s*-\s*(?<info>.+?)
(?=\[\d{4}|\Z) # End record
/gsx
)
{
print 'date: ', "$+{date}\n";
print 'active: ', "$+{active}\n";
print 'executeThread: ', "$+{executeThread}\n";
print 'info: ', "$+{info}\n";
}
}
Output:
date: 2012-09-14 16:55:22,497
active: ACTIVE
executeThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'
+(com.this.perl.seems.kinda.Cool:di sconnectCORBA:154)
info: Well this is just one line text
date: 2012-09-14 16:55:22,498
active: ACTIVE
executeThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'
+(com.this.perl.seems.kinda.Cool:di sconnectCORBA:154)
info: Well this is just multiple line text
With formats Like this
***** Some other text **** then some more text on another line
date: 2012-09-14 16:55:22,499
active: ACTIVE
executeThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'
+(com.this.perl.seems.kinda.Cool:di sconnectCORBA:154)
info: Well once again this is part starts with bracket and blah blah b
+lah
The regex gets a bit 'ugly,' but manageable. Named captures were used, so $+{info} contains the single or multiline INFO text. |