Re: pcregrep match groups

2009-10-22 Thread Dan Wallis
2009/10/16 Chris Allen ca.al...@gmail.com:
 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.

I'm not familiar with pcregrep, nor is my answer related to Perl, but
gnu grep has an -o or --match-only option, which only outputs the
portion of the input that matches your regular expression. I'm not
sure how it handles groups though, so a bit of experimenting would be
needed. I'm sure a quick sed or grep -v will help get rid of the
stuff you don't want.

So, give this a try, and see if it helps:

echo s dir | bconsole | pcregrep -o -M '^Sched.*:\n(.*\n)*?^===$' |
grep -v === | grep -v Sched

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




Re: pcregrep match groups

2009-10-19 Thread Shlomi Fish
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/




pcregrep match groups

2009-10-18 Thread Chris Allen
I'm using pcregrep in a pipeline to match some information for a
network monitoring system.  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)*?
^$'

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?


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