printing a line number using awk

Hi Chaps,
I'm trying to print the line number of a comma delimited file where the second field in the line is blank using AWK. Here is the code I have so far where am I going wrong. It is the last column in the file.

nawk -v x==0 'BEGIN {FS=",";OFS=","} x++ if ($2 == " ") print $x' bob.tst

Do I need to more the variable declaration or is my if a bit dodgy.

Please help.

Regards
Rob....

Hey Rob,
No variable declaration required... awk tracks things like that for you:

# cat test
this,is,a,test,line
this, ,a,test,line,with,the,second,field,blank
this, is,another,test,line,with,a,blank,in,the,second,field,but,the,field,isnt,blank
this, ,is,another,line,with,a,blank,second,field
# awk -F, '{if($2==" ") print NR}' test
2
4

To do it your way, try this:

nawk -F, 'BEGIN {x=1}; {if($2==" ")print x; x++}' test

I suggest incrementing x after you check so that you can start with x=1 (first line).

Hi blowtorch,
thats great - Ihave another question what happens if does not have a space and it just ,, or is , - which means the end of the line I have tried "" but it does nit like that

don't worry guys

awk -F, '{if($2=="") print NR}' test

does the job thanks