非法参考AWK数组(我有麻烦搞清楚AWK) [英] Illegal reference to an array in awk (I am having trouble figuring out awk)

查看:403
本文介绍了非法参考AWK数组(我有麻烦搞清楚AWK)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的脚本是:

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

我收到错误:

awk: line 1: illegal reference to array b

有什么明显错误?

Is there something obviously wrong?

推荐答案

长度(B)是搞乱你,显然不是AWK的每一个执行支持它。你可以这样做,但:

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
}

分裂返回数组中的元素(B在这种情况下)的数目。

split returns the number of elements in the array (b in this case).

这篇关于非法参考AWK数组(我有麻烦搞清楚AWK)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆