Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

egrep Question?

6 views
Skip to first unread message

T

unread,
May 11, 2009, 10:40:51 AM5/11/09
to
Hi:

I was trying to find negative numbers in a file. I found that the
following didn't work:

egrep -e '-[:digit:].[:digit:]' top.sta.rpt

but the following did work:

egrep -e '-[0-9].[0-9]' top.sta.rpt

According to the man page the first one should have worked, unless I'm
missing something which is highly possible.

Thanks
Tom

Alessandro Selli

unread,
May 20, 2009, 10:50:29 AM5/20/09
to
T wrote:
> Hi:
>
> I was trying to find negative numbers in a file. I found that the
> following didn't work:
>
> egrep -e '-[:digit:].[:digit:]' top.sta.rpt

There are square brackets missing:

muser@drone ~ $ cat top.sta.rpt
234
86
-2
57
-651
9743
832
-68732
-7873
muser@drone ~ $ egrep -e '-[[:digit:]].[[:digit:]]' top.sta.rpt
-651
-68732
-7873

Note you'd still miss the -2 negative number, but this might be the
desired behaviour.


Bye,

--
Alessandro Selli http://alessandro.route-add.net
AVVERTENZA: i messaggi inviati a "trappola" non mi arriveranno.
WARNING: messages sent to "trappola" will never reach me.
Chiave PGP/GPG key: EC885A8B

signature.asc

Reginald Beardsley

unread,
May 20, 2009, 6:02:13 PM5/20/09
to
Alessandro Selli wrote:
> T wrote:
>
>>Hi:
>>
>>I was trying to find negative numbers in a file. I found that the
>>following didn't work:
>>
>>egrep -e '-[:digit:].[:digit:]' top.sta.rpt
>
>
> There are square brackets missing:
>
> muser@drone ~ $ cat top.sta.rpt
> 234
> 86
> -2
> 57
> -651
> 9743
> 832
> -68732
> -7873
> muser@drone ~ $ egrep -e '-[[:digit:]].[[:digit:]]' top.sta.rpt
> -651
> -68732
> -7873
>
> Note you'd still miss the -2 negative number, but this might be the
> desired behaviour.
>
>
> Bye,
>

Curious. What egrep are you using? On Solaris 10 U6 x86, /bin/egrep
produced no output w/ your example, but "egrep -e '-[0-9]' " produced
the desired output.

Reg

Alessandro Selli

unread,
Jun 30, 2009, 2:10:40 PM6/30/09
to
Reginald Beardsley ha scritto:

Sorry, I forgot about this matter.

-bash-3.00$ uname -a
SunOS lustro 5.10 Generic_141414-01 sun4u sparc SUNW,Sun-Blade-1000
-bash-3.00$ cat /etc/release
Solaris 10 5/09 s10s_u7wos_08 SPARC
Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
Use is subject to license terms.
Assembled 30 March 2009
-bash-3.00$ which egrep
/usr/xpg4/bin/egrep

/usr/bin/egrep doesn't do the job:

-bash-3.00$ /usr/bin/egrep -e '-[[:digit:]].[[:digit:]]' top.sta.rpt
-bash-3.00$/usr/bin/egrep -e '-[:digit:].[:digit:]' top.sta.rpt
-bash-3.00$

signature.asc
0 new messages