in reply to Can't seem to match from one varibale to next one.

Can we not say match everything from here on out till you match my first varible of date in next line ?

Yes, but only if all of your data is in a single string. As tobyink pointed out, if you're reading your log file line-by line, e.g.:

... while ( $line = <> ) ...

and you've just read the first line of a multiline record, you can't match against the next record's date.

Although tobyink provided an excellent solution, if you don't have an enormous log file, the following option may also help with your situation, as it reads the entire log file into a variable for processing:

logFile.txt:

[2012-09-14 16:55:22,498] [ACTIVE] ExecuteThread: '8' for queue: 'webl +ogic.kernel.Default (self-tuning)' (com.this.perl.seems.kinda.Cool:di + sconnectCORBA:154) INFO - Well this is just one line text [2012-09-14 16:55:22,498] [ACTIVE] ExecuteThread: '8' for queue: 'webl +ogic.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 [2012-09-14 16:55:22,498] [ACTIVE] ExecuteThread: '8' for queue: 'webl +ogic.kernel.Default (self-tuning)' (com.this.perl.seems.kinda.Cool:di + sconnectCORBA:154) INFO - Well once again this is part starts with b +racket and blah blah blah

Script:

use strict; use warnings; my @infos; { local $/; open my $fh, '<', 'logFile.txt' or die $!; my $data = <$fh>; push @infos, $1 while $data =~ /INFO - (.+?)(\[\d{4}|\Z)/gs; } chomp @infos; print join "\n--##--\n", @infos;

Output:

Well this is just one line text --##-- Well this is just multiple line text With formats Like this ***** Some other text **** then some more text on another line --##-- Well once again this is part starts with bracket and blah blah blah

Unless I'm mistaken, you're interested in grabbing the text after the "INFO" in each record. In the script above, @infos will contain that text, and the regex grabs it by matching as you've described, and includes matching on the last line where no date follows.

Hope this helps!

Replies are listed 'Best First'.
Re^2: Can't seem to match from one varibale to next one.
by Ben328 (Novice) on Sep 16, 2012 at 22:52 UTC

    Thanks Kenosis. This is great. On your solution how do i define other variables within the line though? Basically, I also wanted the capability to pull any portion of the line as a variable so that I can compare each variable seperately later on.

    For ex: I want to define variable for ACTIVE ExecuteThread: and so forth as well. Do i do that as follows:

    push @infos, $1, $2, $3, while $data =~ / \ (.+?) \ \s+ \ (.+?) \ ... and so forth

    Does this makes sense? Hopefully, i am asking the right question. In any case, I have been helped tremendously already. Thanks,

      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.