You have an awk script. Is it called ~/bin/sum_dupli_gene.awk make_gene_probe.txt ? That looks more like the argument to -f that you'd pass into the script.
All I can see in the BEGIN section is print ARGV[1]. There's nothing wrong with that. Are you saying it does not work just with that? "#--loads of stuff" doesn't really help us if we can't see that "stuff". Can you be more specific about what you mean by "doesn't work"?
I removed ARGV[1]. The code for loads of stuff looks like:
#!/usr/bin/awk -f
#awk -F'\t' -v OFS='\t' '
BEGIN {
if(NR==1){
header="AffyID"
for(j=2;j<=NF;j++){
header=header"\t"$j
}
}
#---fix headers
else {
#--start with row second
if($2 in gene_arr) {
for(k=3;k<=NF;k++){
#starting with 3rd column. will keep sum array with 3rd too
sum[gene_arr[$2],k]= $k + sum[gene_arr[$2],k]
}
}
else {
#--if gene not in array
gene_arr[$2]=NR
#starting with 3rd column. will keep sum array with 3rd too
for (k=3;k<=NF;k++){
sum[NR,k] = $k;
}
}
}
}
#--processing ends for columns and headers
#-------------------
END{
print header
for (key in gene_arr){
printf key"\t"key"\t"
for(z=3;z<=NF;z++){
#starting with 3rd column. will keep sum array with 3rd too
if(z==NF){ #if last columns
printf sum[gene_arr[key],z]
}
else{
printf sum[gene_arr[key],z]"\t"
}
}
printf "\n"
}
}
#--------------------------
# < make_gene_probe.txt
By doesn't work I mean it prints blank lines. '\n' That's it. No print header or anything.
First question: why are you doing this in the BEGIN section in the first place? It's executed once at the beginning, not for each record (line) in the file.
The field separator is FS. You can either pass it into the script, either from the command line when you invoke the script (by adding -v FS=?), or by setting it in the BEGIN section (with FS=?).
Remember if you invoke the script from the command like with awk -v FS=? -f ..., the shebang is not used.
If you chose to invoke the script directly, e.g. with: ~/bin/sum_dupli_gene.awk make_gene_probe.txt , you can add the -v option there: