Référence illégale à un tableau dans awk (j’ai du mal à comprendre awk)

Le script que j’essaie d’utiliser est le suivant:

cat gatk_probes.interval_list | awk ' BEGIN{ OFS="\t"; print "#CHR\tBP1\tBP2\tID" } { split($1,a,":"); chr=a[1]; if (match(chr,"chr")==0) { chr="chr"chr } split(a[2],b,"-"); bp1=b[1]; bp2=bp1; if (length(b) > 1) { bp2=b[2] } print chr,bp1,bp2,NR }' > ./EXOME.targets.reg 

Je reçois l’erreur:

 awk: line 1: illegal reference to array b 

Y a-t-il quelque chose qui ne va pas?

length(b) vous gâche, apparemment toutes les implémentations de awk ne le supportent pas. Vous pouvez le faire si:

 BEGIN { OFS="\t"; print "#CHR\tBP1\tBP2\tID" } { split($1,a,":"); chr=a[1]; if (match(chr,"chr")==0) { chr="chr"chr } blength = split(a[2],b,"-"); bp1=b[1]; bp2=bp1; if (blength > 1) { bp2=b[2] } print chr,bp1,bp2,NR } 

split renvoie le nombre d’éléments dans le tableau (b dans ce cas).