On 2/10/06, Dermot Paikkos <[EMAIL PROTECTED]> wrote:
snip
> > > Peter> "Error: building module..."  If this pattern is hit I need
> > to copy
> > > Peter> that line and up 25 lines into a new file error.log.
snip
> cat logfile.log | perl -e 'while (<>) { print if /Error/ }'
>
> `perldoc perlrequick` would have given you the answer just as
> quickly.
snip

Except that this doesn't do what he asked.

What he needs is something more like

perl -ne '$print = 25 if /Error: building module/; print if $print-- >
0' logfile.log

if he wants the 25 lines after the error message or

perl -ne 'push @save, $_; shift if @save > 25; if (/Error: building
module/) {print; @save =()}' logfile.log

if he wants the 25 lines before the error message.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to