Date: Mon, 28 Sep 2015 09:12:20 -0400 From: "Chad J. Milios" <milios@ccsys.com> To: "no@spam@mgEDV.net" <nospam@mgedv.net>, freebsd-questions@freebsd.org Subject: Re: 10.2-RELEASE/amd64: grep regex syntax vs. grep-bug Message-ID: <56093CB4.6060606@ccsys.com> In-Reply-To: <00e801d0f9e2$125ec430$371c4c90$@mgedv.net> References: <00e801d0f9e2$125ec430$371c4c90$@mgedv.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On 9/28/2015 7:37 AM, no@spam@mgEDV.net wrote: > hi folks, > the goal: grep, that a variable contains a number and JUST digits. > # setup sample variable - we're on /bin/sh @ 10.2-RELEASE/amd64. > x="" > # od output the content of the variable to ensure content > echo "$x" | od -ctdC > 0000000 \n > 10 > 0000001 > # now try /usr/bin/grep'pin (C locale) that it contains... > # ^ at BOL... > # [0-9] require a digit > # * ... and digits following > # $ ...until we reach EOL > # ... but...: > echo "$x" | grep -c '^[0-9]*$' > 1 <== WHY? > it works if i remove the *, but this would only work for 1digit nrs. > is this a grep bug or my false understanding of how '*' works? > you want to use + (1 or more) instead of * (0 or more) and for that youll need to add -E mode to grep as well
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?56093CB4.6060606>