bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep: echo -en "AB\nA B\n" | egrep 'A?B'


From: p.p.
Subject: Re: grep: echo -en "AB\nA B\n" | egrep 'A?B'
Date: Fri, 14 Dec 2007 18:38:22 +0100 (CET)


> "p.p." <address@hidden> wrote:
> > if I do
> >
> > echo -en "AB\nA B\n" | egrep 'A?B'
> >
> > the result is
> > AB
> > A B
> >
> > while, as I understand it, the second line containing the space should not 
> > match.
> 




--- John Cowan <address@hidden> schrieb:
> The latter.
> 
> Your pattern says to match an optional A followed by a B.  The first
> line has an A followed by a B, so it matches; the second line has a B,
> so it too matches.  The presence of an A on the second line is irrelevant.
> 
> You may want to wrap your pattern in ^ and $ to force it to match the
> whole line.
> 



--- Paul Jarc <address@hidden> schrieb:
> The regexp will match any line that contains "AB" or "B".  If you want
> to match only those lines that are exactly "AB" or "B", with nothing
> else surrouding them, then you have to add beginning- and end-of-line
> anchors:
> egrep '^A?B$'
> 
> Also, you might want to use "grep -E" insteead of "egrep", for the
> sake of portability - only "grep -E" is specified by POSIX.
> 
> 
> paul
> 



ouch, ok, I feel ashamed - you're right.
Actually I had a leading '^'.
I try to reproduce my problem when I'm back on the other computer and in the 
meantime I make a
note to not create minimal examples after 10pm.

peter

@paul: thanks for the "-E" hint, I was always wondering which way is more right.



       __________________________________  Ihre erste Baustelle? Wissenswertes 
für Bastler und Hobby Handwerker. www.yahoo.de/clever




reply via email to

[Prev in Thread] Current Thread [Next in Thread]