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

As a slightly unweildy one-liner:

perl -ne"if(/processed/){ print($last),undef($last) if $last; print;}else{$ +last=$_}" junk.dat **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.

Replies are listed 'Best First'.
Re^2: How to print a matching line and one line above it?
by vbynagari (Initiate) on Apr 20, 2011 at 00:43 UTC
    Thanks for your help. I am kinda new to perl. Can you be a bit more specific on the syntax please?

      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.