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

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

Re: grep


From: Gaute B Strokkenes
Subject: Re: grep
Date: 28 Jun 2001 10:54:36 +0100
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7

On Thu, 28 Jun 2001, address@hidden wrote:
> I found a bug in grep utility.
> 
> I have a file which contains the following lines
> 
> ------
> AS123
> FG32 
> AS435
> -----
> 
> 
> no in command prompt I have given grep command like
> 
> grep [^A] <file_name>
> 
> I expect only FG32 to  be displayed. but it out put was all contents
> of the file. why this behaviour is happening

Because you're asking grep to find lines which contain any character
that is not A.  

You've misunderstood the meaning of "^".  When at the very beginning
of the regexp, it means "this should be the very beginning of the
line".  When it is the first character in a character class (a string
of characters enclosed by [ and ] ) then it means negation, i.e. all
characters that are not explicitly mentioned rather than just those
that are listed.

I hope that makes it clear; if not then please ask.

address@hidden:~$ cat > fubar
AS123
FG32 
AS435
address@hidden:~$ grep ^A fubar
AS123
AS435
address@hidden:~$ grep [^A] fubar
AS123
FG32 
AS435
address@hidden:~$ 

-- 
Big Gaute                               http://www.srcf.ucam.org/~gs234/
I want a VEGETARIAN BURRITO to go..  with EXTRA MSG!!



reply via email to

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