bug-grep
[Top][All Lists]
Advanced

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

Re: grep bug report: --only-matching fails


From: Benno Schulenberg
Subject: Re: grep bug report: --only-matching fails
Date: Sat, 29 Sep 2007 20:08:01 +0200
User-agent: KMail/1.9.7

address@hidden wrote:
> grep -o [1234567890]* grepbug-onlymatching.txt

It is indeed puzzling that the above doesn't produce any output.  
But in a sense the -o and the * are conflicting: the [1234567890]* 
will match anything, also zero digits, and the -o should then print 
all these occurrences of zero digits...

It works when you change the regular expression to be more specific: 
you don't really want to match zero occurrences of a digit, but 
only one or more: 

  grep -o "[1234567890]\+" grepbug-onlymatching.txt

or

  grep -Eo [1234567890]+ grepbug-onlymatching.txt

(Why the quotes are needed in the first alternative is beyond me.)
  
Benno




reply via email to

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