Re: [pcre-dev] How to mimic --only-matching inside of regex

Top Page
Delete this message
Author: Swamisai, Ragavendar
Date:  
To: pcre-dev@exim.org
Subject: Re: [pcre-dev] How to mimic --only-matching inside of regex
Thanks for the quick response.

> Well, you can't do that by anything you try inside the regex, because
> pcregrep either prints the whole line or the part that matched if you
> set the -o option. If you can't use the -o option, you will always get
> the whole line.


I was afraid that would be the case.

> How about piping STDOUT to another instance of pcregrep (or some other
> program) to chop off the text after the .... ? Or do that before
> passing the data to pcregrep?


I have decided that it is better to change the program to be smart to accept pcregrep command line options.

Your response just re-enforced that changing the program is a better option.

Thanks
Raga


> -----Original Message-----
> From: Philip Hazel [mailto:ph10@hermes.cam.ac.uk]
> Sent: Tuesday, September 07, 2010 8:33 AM
> To: Swamisai, Ragavendar
> Cc: pcre-dev@???
> Subject: Re: [pcre-dev] How to mimic --only-matching inside of regex
>
> On Tue, 7 Sep 2010, Swamisai, Ragavendar wrote:
>
> > STRING
> >
> > #ABC_XYZ foo.c(999) @ 19990 ns: foobar [foo] DATA packet mismatch.....
> Data on wire is
> 0000000000000000000000000000063b0000000000000000000000000000063b00000000000
> 00000000000000000063b0000000000000000000000000000063b0000000000000000000000
> 000000000000000000000000000000000000000000000000000000000000000000000000000
> 0
> >
> > I want to print out just the line
> >
> > #ABC_XYZ foo.c(999) @ 19990 ns: foobar [foo] DATA packet mismatch.....
> >
> > I am able to do this if I do the below
> >
> > % pcregrep -o -e "#\s+ABC_XYZ.*\.\.\.\." file.txt
> > #ABC_XYZ foo.c(999) @ 19990 ns: foobar [foo] DATA packet mismatch.....
> >
> > But need a way to do the above without using '-o' option
>
> Well, you can't do that by anything you try inside the regex, because
> pcregrep either prints the whole line or the part that matched if you
> set the -o option. If you can't use the -o option, you will always get
> the whole line.
>
> How about piping STDOUT to another instance of pcregrep (or some other
> program) to chop off the text after the .... ? Or do that before
> passing the data to pcregrep?
>
> Philip
>
> --
> Philip Hazel