bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: possible bug, not sure GNU grep 2.6.3


From: Eric Blake
Subject: Re: possible bug, not sure GNU grep 2.6.3
Date: Mon, 23 Apr 2012 16:23:27 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1

On 04/23/2012 12:01 PM, Mike Hahn wrote:
>    Hi,
>      I got a very unexpected result while using grep.  I have 3 files with
>    IP and dns pairings.  file 1, 2 and 3.  If I use "grep [[:alpha:]] 1" I
>    get the expected results, all the IP addresses with their host name.
>    However, if I use "grep [[:digit:]] 1" I get all IP's from all 3
>    files.  I actually found this by using the -c to count the number of IP
>    addresses.  Much to my surprise I got the results of all 3 files.

This is not a bug in grep, but a mistake in your part for misusing a
shell feature.

>    user:user>grep -c [[:digit:]] 1
>    2:9
>    3:9
>    1:9

Try:

echo grep -c [[:digit:]] 1

and realize that without the echo, the shell expanded that glob to
actually invoke:

grep -c 1 2 3 1

What you meant to use was:

grep -c '[[:digit:]]' 1

so that the shell doesn't interpret the glob, and you actually pass the
one argument "[[:digit:]]" to grep, rather than the three arguments "1",
"2", and "3" (or whatever else happens to match the glob in your current
working directory).

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]