[Israel.pm] context grep in Perl

Gaal Yahas gaal at forum2.org
Mon Nov 28 05:01:35 PST 2011


perl -nle 'BEGIN {$pat = shift @ARGV} push @c, $_; shift @c if @c > 3; $c =
join "\n", @c; print "$c\n----\n" if $c =~ /$pat/o'

Usage:
  <one-liner> REGEXP FILE ...

This hardcodes 3 as the context value, if you want better options (for
example, if you want to use substrings intsead of regexps for matching, -v,
etc.) you probably need more than a single line.

On Mon, Nov 28, 2011 at 2:28 PM, Yossi Itzkovich <
Yossi.Itzkovich at ecitele.com> wrote:

> Hi,****
>
> ** **
>
> In this link : http://docstore.mik.ua/orelly/unix/upt/ch27_13.htm****
>
> They mention cgrep that is implemented in Perl.****
>
> ** **
>
> Does someone have such implementation ?****
>
> Is there a one-liner  ("real" one liner) solution ?****
>
> ** **
>
> Regards****
>
> ** **
>
> Yossi****
>
> This e-mail message is intended for the recipient only and contains
> information which is CONFIDENTIAL and which may be proprietary to ECI
> Telecom. If you have received this transmission in error, please inform us
> by e-mail, phone or fax, and then delete the original and all copies
> thereof.
>
> ______________________________________________________________________
> This email has been scanned by the Symantec Email Security.cloud service.
> For more information please visit http://www.symanteccloud.com
> ______________________________________________________________________
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl
>



-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.perl.org.il/pipermail/perl/attachments/20111128/388582b3/attachment.htm 


More information about the Perl mailing list