[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grep: echo -en "AB\nA B\n" | egrep 'A?B'
From: |
Paul Jarc |
Subject: |
Re: grep: echo -en "AB\nA B\n" | egrep 'A?B' |
Date: |
Fri, 14 Dec 2007 12:17:31 -0500 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
"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.
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