New Eyes on an awk script
Brad De Vries
devriesbj
Mon Nov 15 16:27:46 PST 2004
On Mon, 15 Nov 2004 09:55:13 -0500, Kurt Wall <kwall at kurtwerks.com> wrote:
> On Mon, Nov 15, 2004 at 06:01:23AM -0800, Shawn Tayler took 69 lines to write:
> > Thanks Brad,
> >
> > Well this did change something. The syntax error now points to the '&&" in
> > the if statements. According to my not so great SED & AWK book from
> > O'Reilly, this is supposed to be a logical AND.
> >
> > Any suggestions?
>
> You've got a a typo somewhere. This script:
>
> --- cut ---
> BEGIN { FS = "," }
> {
> ++x
> if (NF == 9) { print x","$1","$2","$3","$4","$5","$6","$7","$8","$9",NA"
> }
> if ((NF == 10) && ($9 == $10)) { print x","$1","$2","$3","$4","$5","$6","$7","$8","$9",NA" }
> if ((NF == 10) && ($9 != $10)) { print x","$1","$2","$3","$4","$5","$6","$7","$8","$9","$10 }
> if (NF == 8) { print x","$1","$2","$3","$4","$5","$6","$7","$8", , " }
> }
>
> --- cut ---
>
> on this data:
>
> --- cut ---
> a,b,c,d,e,f,g,h,i
> a,b,c,d,e,f,g,h,i,j
> a,b,c,d,e,f,g,h,i,i
> a,b,c,d,e,f,g,h
> --- cut ---
>
> produces this output:
>
> $ awk -f x.awk < data
> 1,a,b,c,d,e,f,g,h,i,NA
> 2,a,b,c,d,e,f,g,h,i,j
> 3,a,b,c,d,e,f,g,h,i,NA
> 4,a,b,c,d,e,f,g,h , ,
>
> Kurt
> --
> Democracy is good. I say this because other systems are worse.
> -- Jawaharlal Nehru
Kurt, I have to ask why you think there was a typo in the script. It
looked like it worked to me.
Brad.
More information about the Linux-users
mailing list