[Israel.pm] context grep in Perl

Levenglick Dov-RM07994 RM07994 at freescale.com
Mon Nov 28 07:16:07 PST 2011


Show off :)

 
Best Regards,
Dov Levenglick
SmartDSP OS Development Leader
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Gaal Yahas
Sent: Monday, November 28, 2011 15:03
To: Perl in Israel
Subject: Re: [Israel.pm] context grep in Perl

Sorry, the match should be $_ =~  /$pat/o, and not against $c, to reduce dupes.
On Mon, Nov 28, 2011 at 3:01 PM, Gaal Yahas <gaal at forum2.org> wrote:
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/




-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/


More information about the Perl mailing list