* On Tuesday 2005-08-23 at 16:24:05 +0200, Stepan Kasal wrote: > > Sure, I understood that. That's what > sed 's/a*/X/g' > or > awk 'gsub(/a*/,"X")' > does. > > Your arguments seem to show that grep should print only lines > with _nonempty_ matches. (Empty pattern might be an exception.) > But that's too late to change.
Hmmm. I may require more thought before we commit to anything. To state explicitly what you probably already understood (I'm thinking out loud here), the way grep currently works is: -- To first identify which lines contain matches (both empty and non-empty) so that in the case of a 'a*'-type pattern, every line will match at that step. I assume that's the part you say is too late to change. -- Then, since there are no non-matching lines in that case anyway, all line are screened for matches to display in both the --only-matching and --color cases (otherwise they are just displayed right away). The question at this step is only non-empty matches or all matches regardless of their length. > With current setup, the inconsistency will show up because > grep --colour 'a*' > will then print lot of lines without any colour tags. > It might be confusing for X-ray robots who expects to see the > tags... Especially for non-empty matches. > I wanted to prefer consistency. Then I'd have to teach people that they > shouldn't use patterns which match empty string. Indeed, that's what users should really do. Let's warn about it in the docs. > You wanted to change the specification of --only-matching (--colour), > so that it prints (colorifies) only non-empty matches. Yes. Note that there is in fact no specification since this is a GNU extension that POSIX or others don't know or say anything about. Hence probably the current implementation which also shows the inconsistency, but with a difference in degree. > OK, I no longer object to it. But please change the decumentation > (info and manpage) so that it states this clearly. Ok. I will put this under --only-matching and --color.