Awk: syntax error

awk -F, ' NR>1 {

BEGIN{
chr[$1]=$2
}
END{
for (k in chr) {print k}
}


} ' $gene_file

I've a really simple code. I want to store gene name and it's chromosome and in the end print them.
I'm skipping line one as it contains headers.

But I don't know why I get error as:

awk: cmd. line:1: BEGIN{
awk: cmd. line:1: ^ syntax error
awk: cmd. line:4: END{
awk: cmd. line:4: ^ syntax error
[ss5505@hgrcgrid non_synonymous]$

AWK goes..

awk 'BEGIN { do this }
NR > 1 { .. }
...
END { do that }
'

BEGIN should not be preceded by a { - it's not based on any condition (such as NR > 1), it's just the first thing AWK does. Similarly, END should not be followed by a } as it's not part of any condition - it's the last thing AWK does.

Hello genome,

Since you haven't shown us sample Input_file so based on seeing your code, could you please try following and let me know if this helps you.

awk -F, 'BEGIN{
print "my being section here...."
}
NR>1{
chr[$1]=$2
}
END{
for (k in chr) {print k}
}
'   Input_file
 

Thanks,
R. Singh