NetBSD-Bugs archive

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

Re: bin/43896: grep -o match problem



The following reply was made to PR bin/43896; it has been noted by GNATS.

From: David Holland <dholland-bugs%netbsd.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: bin/43896: grep -o match problem
Date: Mon, 27 Sep 2010 02:17:47 +0000

 On Wed, Sep 22, 2010 at 03:55:00PM +0000, peter%kerwien.homeip.net@localhost 
wrote:
  > The following command fails to match properly:
  > 
  > echo VERSION=10 | grep -o '[0-9]*'
  > 
  > The result is empty. The correct result should be 10.
 
 This result is, though perhaps not useful, correct. You can see what's
 going on if you try sed:
 
    % echo VERSION=10 | sed 's/[0-9]*/wibble/'
    wibbleVERSION=10
    % 
 
 Because [0-9]* matches the empty string, grep is matching the empty
 string at the beginning of the line and printing that.
 
 To get the result you're looking for, try grep -o '[0-9][0-9]*' or
 egrep -o '[0-9]+'.
 
 -- 
 David A. Holland
 dholland%netbsd.org@localhost
 


Home | Main Index | Thread Index | Old Index