bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: Grep problem


From: Bob Proulx
Subject: Re: Grep problem
Date: Sat, 1 Oct 2005 12:20:54 -0600
User-agent: Mutt/1.5.9i

Gummadi, Latha C wrote:
> 1) yes | grep -m 3 y
>       a)This command works fine on my SuSE machine [LinuxSET Image
> SLES9-1 Revision 7, SUSE LINUX Enterprise Server 9 (x86_64),Kernel
> 2.6.5-7.145lxset1-smp]. "grep"  
> 
>         version on this machine is 2.5.1

Sounds good.

>       b)This command does not work on my Red-Hat Linux machine [LinuxSET
> Image 7.1.4 (Gold) Revision 19, Red Hat Linux release 7.1
> (Seawolf)Kernel 2.4.9-45lxset34smp ]
> 
>         version on this machine is 2.4.2

Looking at the CVS logs I see that support for the -m option was added
just after that version.  No -m support was available in 2.4.2.  You
will need to upgrade grep on that machine in order to get the newer
functionality.

>       c)This command does not work on my Sun OS machine [SUNOS RELEASE:
> 5.8, Architecture: sun4u, Model: SUNW,Sun-Fire-280R]. Neither of  grep
> -version, uname -a work on this machine.

As pointed out by John Cowan you are probably not using GNU grep
there.  Otherwise --version would work.  You will need to verify that
you are really using GNU grep.

> 2) Command I was trying to execute was `ls -l | grep -m 3 preview` in a
> specific directory. I was trying this on my Sun machine and I kept
> getting following error message.
> 
>       grep: illegal option -- m
> 
> grep: illegal option -- 3
> 
> Usage: grep -hblcnsviw pattern file . . .

That indicates that the --max-count feature is not installed in that
version of grep.

As suggested by Stepan Kasal you can use other commands to do the same
thing that grep --max-count is doing.  If you are unable to upgrade or
install the new grep on those machines I suggest using alternatives.
Here is one way.

  yes | awk '/y/ { if (++c > 3) exit; print; }'
  y
  y
  y

Bob




reply via email to

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