grep [A-Z] returns unmatched lines
Hello new linux user (2 months) first question
does anyone know why something like: echo lowercase | grep [A-Z] would still return the lowercase line even tho there is no match? Using --color will show there is no match but the line is still returned. I am still new but from what i've learned this should not work like that. ubuntu 10.10 Thanks in advance |
It doesn't return a match on my system:
Code:
$ echo lowercase | grep [A-Z] |
Perhaps [A-Z] is being expanded by the shell as illustrated in this command prompt session:
Code:
c@CW8:/tmp$ touch A |
22:11:28 ~:$ echo lowercase | grep [A-Z]
lowercase 22:11:53 ~:$ echo UPpercase | grep [A-Z] UPpercase 22:12:22 ~:$ bash --version GNU bash, version 4.1.5(1)-release (i686-pc-linux-gnu) Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. 22:12:41 ~:$ grep --version GNU grep 2.6.3 Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. 22:16:07 ~:$ echo UPpercase | grep --color [A-Z] UPpercase The "UP" in UPpercasse was returned red. |
Quote:
lowercase no dice i guess my grep is just stupid |
Not necessarily :)
Do you have any aliases that could be interfering? Code:
$ alias |
In my case it works fine. But i am using a different bash version running on RHEL 5.4
[xkinved@einbalx ~]$ echo lowercase |grep '[A-Z]' [xkinved@einbalx ~]$ bash --version GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2005 Free Software Foundation, Inc. [xkinved@einbalx ~]$echo LOwercase |grep '[A-Z]' LOwercase |
Also, one other thing you can try: tell bash to tell you what it's doing :)
Code:
$ set -x You turn off the extra info from bash by executing "set +x" when you're done. |
Code:
alias egrep='egrep --color=auto' |
Code:
alias egrep='egrep --color=auto' Code:
22:39:38 ~:$ set -x |
I have to say that's a bit bizarre. I did notice that 2.6.3 was on the tail end of a rapid-fire release session as indicated in the release notes here.
What I'll do is download the source for 2.6.3, compile, and run it to see if I get the same result as you. There was no 2.6.4 release, and the 2.7 release (5 months after 2.6.3) doesn't seem to mention a bug fix that would explain this (here). Off to compile and test... |
Try echo $GREP_OPTIONS
|
After compiling, I can confirm that 2.6.3 is spitting out a bad result.
Code:
$ mkdir temp_grep And as a follow-up, I downloaded the 2.7 source, compiled and ran. 2.7 gives the expected output (i.e. nothing). So it seems there is a bug in 2.6.3, but that bug appears to be fixed in 2.7. |
Sometimes it has to do with your locale. Try a different locale like C, and see.
|
All times are GMT -5. The time now is 08:44 PM. |