in reply to Re^2: How to print a matching line and one line above it?
in thread How to print a matching line and one line above it?
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
|
|---|