2

The script I am trying to use is:

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

I am getting the error:

awk: line 1: illegal reference to array b

Is there something obviously wrong?

4

1 回答 1

3

length(b) is messing you up, apparently not every implementation of awk supports it. You can do this though:

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 returns the number of elements in the array (b in this case).

于 2013-02-06T04:21:22.403 回答