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

gawk: bug or feature?



Hi,
this is not -probably- debian specific, but I have no other distribution to
test, so here's my question.

I'm filtering a file using gawk. since there are line that look alike, but
differ only by two chars, I decided to take this approach:

/pattern/	{ if line-of-type-1 {
                    FIELDWIDTHS=fields1; 
		    flag=1;
		} else {
		    FIELDWIDTHS=fields2;
		    flag=2;
		}

flag==1		{ do something }
flag==2		{ do something else }

my understanding of gawk working:

get a line from file
scan pattern in order of appearance and if a match is found, execute action
until end-of-file

so it should do:
get line 1
decide if it's type-1 or type-1 and set FIELDWIDTHS accordingly
apply FIELDWITDHS using one of the "do something" rules

instead, this is what I see:
FIELDWIDTHS is correctly assigned the right record len spec.

BUT

lines are splitted using the previous value of FIELDWITDHS (for ex, the
first line is splitted without caring of FIELDWIDTHS). by 'previous value I
mean the value FIELDWIDTHS had before /pattern/ rule.

I've tested this behaviour with gawk 3.0.0, 3.0.1 and 3.0.2, with debian
distribs from 1.1 to 2.0. same behaviour. so maybe this is the intended way
of working for awk. is this the right answer? I've read awk manpage, but ..
I don't find anything that confirms or denies it.
Can anybody help me? I'd submit a bugreport, if this is a bug. but I don't
want to bother the mantainer, if I'm wrong.

sorry for my english. TIA
-- 
||    || |||||||  Marco Frattola                     Microsoft is not the answer
||`..'|| |||...   Piacenza, Italy                    Microsoft is the question
|||  ||| |||''    mfrattola@enjoy.it                 "No" is the answer
|||  ||| |||      www.enjoy.it/users/~mk/index.html  Live Linux, live free!


Reply to: