in reply to Re^2: need to extract top and bottom lines...
in thread need to extract top and bottom lines...

You can add a little logic to the one-liner to cope with more general cases where some ERROR messages don't span two lines (assuming messages all start with a timestamp).

perl -ne 'sub BEGIN {$l="";}$l=$_, next unless /ERROR/;print /^[^12]/ +? "$l$_" : $_;$l=$_;' some.log

Not Y3K compliant.

JohnGG

Note: something is eating the square brackets around the character class ^12 for some reason. Code tags don't help.

Replies are listed 'Best First'.
Re^4: need to extract top and bottom lines...
by johngg (Canon) on Dec 16, 2004 at 11:20 UTC
    Oops, something ate the square brackets around the negated character class ^12. Maybe code tags will help, maybe not.

    perl -ne 'sub BEGIN {$l="";}$l=$_, next unless /ERROR/;print /^[^12]/ +? "$l$_" : $_;$l=$_;' some.log

    Johngg