Grep/egrep

HHunt

Supreme [H]ardness
Joined
Apr 12, 2001
Messages
6,063
Edit: Ok, it helped when I remembered to use double square brackets, now I'm down to one odd problem.

Grep is usually case sensitive unless you specify -i. So why does this happen?
Code:
[dnebdal@mix ~]$ ls|egrep  -x "[a-z]{1,5}"
C
Mail
mbox
NET
proj
Sent
tid
tom
Trash
WEB
[dnebdal@mix ~]$ ls|egrep  -x "[A-Z]{1,5}"
C
Mail
mbox
NET
proj
Sent
tid
tom
Trash
WEB
[dnebdal@mix ~]$

As for the setting: RHEL 64-bit, bash 2.00.15, and GNU grep 2.5.1 .
Doesn't happen on my FreeBSD/tcsh/same version of grep box.

edit again:
[[:lower:]] and [[:upper:]] work as expected. I suspect it's an artifact of the LANG envvar, which is no_NO. It's still weird.
 
It does indeed seem to be a result of setting your LANG envvar to no_NO.

Here's my tests:
Code:
lisa@helium hhunttest $ export LANG='en_US'
lisa@helium hhunttest $ ls|egrep  -x "[a-z]{1,5}"
mbox
proj
tid
tom
lisa@helium hhunttest $ ls|egrep  -x "[A-Z]{1,5}"
C
NET
WEB

Code:
lisa@helium hhunttest $ export LANG='no_NO'
lisa@helium hhunttest $ ls|egrep  -x "[a-z]{1,5}"
C
Mail
mbox
NET
proj
Sent
tid
tom
Trash
WEB
lisa@helium hhunttest $ ls|egrep  -x "[A-Z]{1,5}"
C
Mail
mbox
NET
proj
Sent
tid
tom
Trash
WEB

Was going to post no_NB but that locale isn't available. Sounds very odd.

app-shells/bash-3.1_p17
sys-libs/glibc-2.3.6-r3
 
And just for fun, it does not happen with FreeBSD libc when LANG is no_NO.
(LANG wasn't set when I tried earlier, and this time I tried both tcsh and bash, just in case.)
 
Yeah, doesn't happen here either with LANG set to en_US.ISO8859-1 on a FreeBSD machine. :)
 
As expected:
Code:
[dnebdal@mix ~]$ ls | egrep -x "[A-Z]{1,4}"
C
Mail
mbox
NET
proj
Sent
tid
tom
WEB
[dnebdal@mix ~]$ export LANG=en_US.ISO8859-1
[dnebdal@mix ~]$ ls | egrep -x "[A-Z]{1,4}"
C
NET
WEB
[dnebdal@mix ~]$

I wonder if this has been submitted as a bug.
edit: Doesn't look like it. (That's "bugs in libc / regexp, all bug states".)
 
Back
Top