bug-grep
[Top][All Lists]
Advanced

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

[bug #11579] "echo ab | grep -o ^." gives incorrect output


From: anonymous
Subject: [bug #11579] "echo ab | grep -o ^." gives incorrect output
Date: Sat, 25 Jun 2005 04:50:45 +0000
User-agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.3) Gecko/20040910

Follow-up Comment #1, bug #11579 (project grep):

This bug also applies to other anchors (\<,\>,\b, etc.)
echo A llittle problem | grep -o "\<l"
responds with two matches instead of one.
Also,
echo A llittle problem | grep --color "\<l"
colors both l's in llittle, when it should only color the first one.

I suspect, though I have not looked at the code, that since grep was
originally designed to show the entire line of input if any part of the line
matches the expression, it originally stopped searching for a pattern after
the first match. When the -o (and later the related --color) option was added,
to be able to show all the matches on a line, the regular expression search
was restarted on the line at the point of the last match as though it was the
beginning of the line. Hence,
echo This is a  liittle problem | grep -E --color "(\<l)|(^i)"
colors the lii in liitle.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?func=detailitem&item_id=11579>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





reply via email to

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