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

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

Re: GAWK bug ?


From: John Cowan
Subject: Re: GAWK bug ?
Date: Mon, 19 Jun 2006 15:17:28 -0400
User-agent: Mutt/1.3.28i

Celsus English scripsit:

> Hi - methinks I found a bug in gawk 

It's not a bug.

> Add2csv.txt which works nicely DID contain
> {if ($6 !~ PAR1) print $0
>            else print $0","PAR2}
> 
> However I wanted the matching to be case-insensitive so I tried to put
> IGNORECASE = 1
> at the start of Add2csv.txt
> 
> This DOUBLED-UP the number of records output - each line was duplicated !!!

Remember that Awk statements are of the form pattern-action.  Here
you have a patterm "IGNORECASE = 1" which is always true, and
an empty action, which is equivalent to the action "{ print $0 }".

What you want is:

BEGIN {IGNORECASE = 1}

which means that when the BEGIN pattern matches (namely, only
at the beginning of the input), the action "IGNORECASE = 1" is
performed.

-- 
John Cowan  address@hidden  http://ccil.org/~cowan
If I have seen farther than others, it is because I was standing on
the shoulders of giants.
        --Isaac Newton




reply via email to

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