PLEASE HELP A NEWBIE: grep doesn't grep

PLEASE HELP A NEWBIE: grep doesn't grep

Post by MIM » Tue, 28 Nov 2000 04:00:00



Hi,
I apologise for potentially stupid question. I'm working through Ellie
Quigley's "LINUX shells by example" and just encountered a problem which I
can't resolve on my own.

When I type
$ grep [A-Z]
and then enter letters from the console, the command seems to be unable to
distinguish between upper and lower cases (I checked in .bash_profile,
there's no alias for "grep -i" there), like this:
aa <--- my input
aa <--- grep's output
AA
AA
BB
BB
11
22
33
which means that the damn thing understands the difference between a letter
and a digit but refuses to distinguish between upper and lower cases.

There is a workaround to use [:upper:] and [:lower:] instead of [A-Z] amd
[a-z] but it's not good enough because all scripts using grep with regular
expressions will fail.

WHAT SHOULD I DO?!!

I'm running Mandrake 7.2, grep's version 2.4.2 (I think).

PLEASE HELP ME SOLVE THIS PUZZLE

 
 
 

PLEASE HELP A NEWBIE: grep doesn't grep

Post by Manfred Bart » Tue, 28 Nov 2000 04:00:00



> Hi,
> I apologise for potentially stupid question. I'm working through Ellie
> Quigley's "LINUX shells by example" and just encountered a problem which I
> can't resolve on my own.

> When I type
> $ grep [A-Z]
> and then enter letters from the console, the command seems to be unable to
> distinguish between upper and lower cases (I checked in .bash_profile,
> there's no alias for "grep -i" there), like this:
> aa <--- my input
> aa <--- grep's output
> AA
> AA

Maybe you are inheriting an alias or a shell function from a parent
shell or there is a global alias or shell function.  Have a look in
/etc/profile (and possibly /etc/bashrc).

To help you see what is going on use the ``type'' command as in
these examples:

$ type -a ls
ls is a function
ls ()
{
    /bin/ls -s -F -T 0 --color=yes $*

Quote:}

ls is /bin/ls
$
$ type -a dos
dos is aliased to `dos-sane'
dos is /usr/bin//dos
$

To make sure you use the program without any hidden options refer to
it by its full path-name, e.g. /bin/grep

$ echo -e "abc\nABC" | /bin/grep [A-Z]
ABC
$

Also have a quick look at:

man which
man file

Does it work now?
--
Manfred

 
 
 

PLEASE HELP A NEWBIE: grep doesn't grep

Post by MIM » Fri, 01 Dec 2000 04:00:00


Thanks for answering, Manfred, but nothing worked for me. Damn!
I checked all relevant environment variables, runned /bin/grep but it still
returns both "ab" and "AB".

Do you by any chance know which RPM this utility usually comes in? I've got
a copy of earlier Mandrake 7.1 (and, I think, even anchient things like
Caldera 2.1) so could try to use earlier versions of grep -- just to be sure
the problem is in the damn program.

Thanks a lot!



> > Hi,
> > I apologise for potentially stupid question. I'm working through Ellie
> > Quigley's "LINUX shells by example" and just encountered a problem which
I
> > can't resolve on my own.

> > When I type
> > $ grep [A-Z]
> > and then enter letters from the console, the command seems to be unable
to
> > distinguish between upper and lower cases (I checked in .bash_profile,
> > there's no alias for "grep -i" there), like this:
> > aa <--- my input
> > aa <--- grep's output
> > AA
> > AA

> Maybe you are inheriting an alias or a shell function from a parent
> shell or there is a global alias or shell function.  Have a look in
> /etc/profile (and possibly /etc/bashrc).

> To help you see what is going on use the ``type'' command as in
> these examples:

> $ type -a ls
> ls is a function
> ls ()
> {
>     /bin/ls -s -F -T 0 --color=yes $*
> }
> ls is /bin/ls
> $
> $ type -a dos
> dos is aliased to `dos-sane'
> dos is /usr/bin//dos
> $

> To make sure you use the program without any hidden options refer to
> it by its full path-name, e.g. /bin/grep

> $ echo -e "abc\nABC" | /bin/grep [A-Z]
> ABC
> $

> Also have a quick look at:

> man which
> man file

> Does it work now?
> --
> Manfred

 
 
 

PLEASE HELP A NEWBIE: grep doesn't grep

Post by Manfred Bart » Fri, 01 Dec 2000 04:00:00



> Thanks for answering, Manfred, but nothing worked for me. Damn!  I
> checked all relevant environment variables, runned /bin/grep but it
> still returns both "ab" and "AB".

Ok.  It wouldn't be the first time that redface has patched a long
established bugfree utility into a buggy mess.  :(

If you have software development support installed get the source and
compile it yourself.  Gnu grep is available from many sites, I get it
from <http://mirror.aarnet.edu.au/pub/gnu/grep/>

then do this:
    mkdir mynewdir
    cd mynewdir
download the grep source archive.
    tar zvtf grep-2.4.tar.gz | less
this shows you what would be unpacked and where it goes.
    tar zxf grep-2.4.tar.gz
    cd grep-2.4
    ./configure --prefix=/
    make
    make check
All tests should pass.  Now do your own test:
    cd src
    echo -e "abc\nXYZ" | ./grep "[A-Z]"
If that works as it should then become root and:
    make install
Done.

--
Manfred

 
 
 

PLEASE HELP A NEWBIE: grep doesn't grep

Post by Erik Max Franci » Fri, 01 Dec 2000 04:00:00



> Thanks for answering, Manfred, but nothing worked for me. Damn!
> I checked all relevant environment variables, runned /bin/grep but it
> still
> returns both "ab" and "AB".

Looks to me like the problem might be something as simple as your shell
globbing the [A-Z] pattern you're using.  Try instead like:

    grep '[A-Z]' ...

Most shells will glob characters closed into brackets before it even
gets to the called program.

--

 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Now I must follow them!
\__/ Beowulf, King of the Geats
    Computer science / http://www.alcyone.com/max/reference/compsci/
 A computer science reference.

 
 
 

PLEASE HELP A NEWBIE: grep doesn't grep

Post by Manfred Bart » Fri, 01 Dec 2000 04:00:00



Quote:> Looks to me like the problem might be something as simple as your shell
> globbing the [A-Z] pattern you're using.  Try instead like:

>     grep '[A-Z]' ...

> Most shells will glob characters closed into brackets before it even
> gets to the called program.

Arrrg!

Never occurred to me.
I nearly always use quotes because the regex are normally more complex.

Just checking:
            ~$ mkdir test
            ~$ cd test
            ~/test$ echo [A-Z]
            [A-Z]
            ~/test$ echo [a-z]
            [a-z]
            ~/test$ touch x
            ~/test$ echo [A-Z]
            [A-Z]
            ~/test$ echo [a-z]
            x
            ~/test$ touch A
            ~/test$ echo [A-Z]
            A
            ~/test$ echo [a-z]
            x
            ~/test$

Yes, that explains it.  Thanks!

ALWAYS use quotes with regex!!!

--
Manfred

 
 
 

PLEASE HELP A NEWBIE: grep doesn't grep

Post by MIM » Tue, 05 Dec 2000 22:04:04


Thanks a lot for your help, Manfred
It all works perfectly now!



> > Thanks for answering, Manfred, but nothing worked for me. Damn!  I
> > checked all relevant environment variables, runned /bin/grep but it
> > still returns both "ab" and "AB".

> Ok.  It wouldn't be the first time that redface has patched a long
> established bugfree utility into a buggy mess.  :(

> If you have software development support installed get the source and
> compile it yourself.  Gnu grep is available from many sites, I get it
> from <http://mirror.aarnet.edu.au/pub/gnu/grep/>

> then do this:
>     mkdir mynewdir
>     cd mynewdir
> download the grep source archive.
>     tar zvtf grep-2.4.tar.gz | less
> this shows you what would be unpacked and where it goes.
>     tar zxf grep-2.4.tar.gz
>     cd grep-2.4
>     ./configure --prefix=/
>     make
>     make check
> All tests should pass.  Now do your own test:
>     cd src
>     echo -e "abc\nXYZ" | ./grep "[A-Z]"
> If that works as it should then become root and:
>     make install
> Done.

> --
> Manfred

 
 
 

1. grep octal value (grep '\0145' /tmp/test) doesn't work !!

Hey There,

I hope someone can assist me in this matter since I can't figure out how to
use grep in this matter.

I have a file test containing hello, - and would like to use grep to search
for an 'e', - but I want to specifying the 'e' with octal value, - with this
solution I can then search for octal zeroes (\00) in text files/binary files
which is actually what i want. But I can't make it work with $grep '\0145'
test ; for some reason.

Am I missing something something basic here ??? any answer appreciated.

Best regards  /Tommy

2. So Long And Thanks For All The Fish (was Re: WINE on a 486)

3. grep sTerm * | grep -v grep ???

4. Future Domain

5. tail | grep | grep | grep

6. RFC 822 Specific Library Routines

7. How to make grep select both lines using only a single 'grep' command

8. Convert DOS .EXE to Linux Binary

9. grep question New to grep

10. Problem using grep through the unix shell: doesn't accept a regular expression in filename

11. Why doesn't grep work in tcl?

12. Bug in grep or man grep

13. simple grep & find script doesn't work under AIX 3.2