in reply to Re: How to print a matching line and one line above it?
in thread How to print a matching line and one line above it?

Thanks for your help. I am kinda new to perl. Can you be a bit more specific on the syntax please?
  • Comment on Re^2: How to print a matching line and one line above it?

Replies are listed 'Best First'.
Re^3: How to print a matching line and one line above it?
by BrowserUk (Patriarch) on Apr 20, 2011 at 00:56 UTC

    C:\test>type junk86.pl #! perl -sw use strict; my $last; while( <> ) { if( /processed/ ){ if( $last ) { print( $last ); undef( $last ) } print; } else{ $last = $_; } } C:\test>type junk.dat **start abc **start adl **start xyz File1 processed File2 processed **start zxcv **start wert File3 processed File4 processed C:\test>junk86 junk.dat >junk.new C:\test>type junk.new **start xyz File1 processed File2 processed **start wert File3 processed File4 processed

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.