LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   grep [A-Z] & [a-z] match both upper and lower case. (https://www.linuxquestions.org/questions/linux-general-1/grep-%5Ba-z%5D-and-%5Ba-z%5D-match-both-upper-and-lower-case-327916/)

jschiwal 05-28-2005 05:19 AM

grep [A-Z] & [a-z] match both upper and lower case.
 
I am using SuSE Linux 9.2
I noticed that grep ( version 2.5.1 ) matches the lower case letters when using the character range [A-Z].
For example: echo "mc C" | grep '[A-Z][A-Z] [A-Z]'
mc C
Sed behaves the same way.

After setting the environmental variable LC_ALL='C' grep behaves as expected.
My $LANG variable is en_US.UTF-8.

Is this behavior normal, or does it indicate that I have a bad locale setting, or some other goofy configuration setting?

One moral is to use [[:upper:]] and [[:lower:]] in scripts.

druuna 05-28-2005 06:07 AM

Hi,

As stated in the (grep) manpage: This is a locale issue (see the REGULAR EXPRESSIONS section).

Quote:

To obtain the traditional interpretation of bracket expressions, you can use the C locale by setting the LC_ALL environment variable to the value C.
This is normal behaviour.

Hope this helps.

jschiwal 05-28-2005 06:25 AM

That is what I did to obtain the behaivior that I was expecting. I read it in the grep man-page. Is it normal to have the LC_ALL='C' setting by default? I believe it was set that way for the root user.

druuna 05-28-2005 06:38 AM

Hi again,

I know that root has the LC_ALL=C setting by default. All my other users also have this setting ('we' are not concerned with other locale settings.).

If I do remember correctly, an english(/american) Suse install will give all users the LC_ALL=C setting. Guess that choosing another language will set a different LC_ALL setting.

I'm currently using suse (old 8.2 version) lfs and slackware. All have LC_ALL set to C for all users. All installs are english, no fiddling with other language settings.

Hope this clears things up a bit.

jschiwal 05-28-2005 06:43 AM

Either I accidentally removed a setting somewhere, or it was reset when I added Russian support.


All times are GMT -5. The time now is 05:59 PM.