in reply to Help parsing badly constructed logfiles

I don't suppose fixing whatever's creating those logfiles is an option?

Here's what I might do: remember the previously-read line, and match your search term against both the current line and the concatenation of the previous and current line. Off the top of my head (completely untested):

my $previous = ""; while(defined(my $line = <>)) { chomp $line; ($previous . $line) =~ m/$pattern/ and say $line; $previous = $line; }

(This isn't perfect, obviously; it'll also print lines where the previous line just so happened to match, even though there's no match across the line boundary. But it should get you started.)

Replies are listed 'Best First'.
Re^2: Help parsing badly constructed logfiles
by Amblikai (Scribe) on Jul 13, 2014 at 17:14 UTC

    That's great advice. I hadn't thought of that!

    I'm still trying to get to the bottom of what is causing the logfile to be so badly formatted. It seems it might actually be the platform LSF which is messing with the output files somehow. I have little to no experience of using the LSF though, (which is another problem!)

    Thanks again!