Hi Chris!

On Friday 16 Oct 2009 22:55:04 Chris Allen wrote:
> I'm using pcregrep in a pipeline to match some information for a
> network monitoring system.  

PCRE is the not-so-Perl-compatible Regular Expression library. It's probably a 
pretty nice as a way to provide Perl-like (but different) regular expressions 
for programs written in C, C++ and other languages, but it's something that we 
Perl people may opt not to help you with because it's not written in Perl or 
is Perl-compatible.

GNU grep's -P flag is similar, and as much as I am fond of it, it again uses 
PCRE. Too bad, though, that it is often absent from /bin/grep (as is the case 
for Debian and Ubuntu) due to the fact that pcre belongs in /usr/bin.

You may wish to look at ack - http://betterthangrep.com/ - for a Perl-based 
implementation of an improved grep, that can act as a filter too, but has some 
other advantages (and possibly some cases where it will be less good).

> I'm having a bit of a problem doing this
> smoothly with the least amount of code.  One thing in particular is
> driving me crazy - I can't figure out how to output only the contents
> of my match groups with pcregrep.
> 
> Here's what I'm doing:
> 
>       echo status dir | bconsole | pcregrep -M '^Sched.*:\n(.*\n)*?
> ^====$'

You can try using 

<<<<
perl -0777 -p -e 'print $1 if m{^Sched.*:\n(.*\n)*?^====$}ms'
>>>>

(Untested)

Instead.

> 
> I only want pcregrep to write to stdout the data in match group 1, ie
> the stuff inside (.*\n)
> 
> Is there a way to do this with pcregrep?
> 

No idea, but there probably is with perl -e and similar 
http://perldoc.perl.org/perlrun.html flags.

Regards,

        Shlomi Fish

-- 
Sent from an iPhone owned by an iLoser.

-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to