New Eyes on an awk script

Kurt Wall kwall
Mon Nov 15 09:47:42 PST 2004


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


More information about the Linux-users mailing list