awk嵌套冰壶托架

时间:2012-11-16 11:16:03

标签: awk parentheses

我有以下awk脚本,我似乎需要下一个大括号。但是在awk中不允许这样做。我如何在我的脚本中修复此问题?

问题在于if(inqueued == 1)。

BEGIN { 
   print "Log File Analysis Sequencing for " + FILENAME;
   inqueued=0;
   connidtext="";
   thisdntext="";
}

    /message EventQueued/ { 
     inqueued=1;
         print $0; 
    }

     if(inqueued == 1) {
          /AttributeConnID/ { connidtext = $0; }
          /AttributeThisDN / { thisdntext = $2; } #space removes DNRole
     }

    #if first chars are a timetamp we know we are out of queued text
     /\@?[0-9]+:[0-9}+:[0-9]+/ 
     {
     if(thisdntext != 0) {
         print connidtext;
             print thisdntext;
         }
       inqueued = 0; connidtext=""; thisdntext=""; 
     }

2 个答案:

答案 0 :(得分:2)

尝试改变

  if(inqueued == 1) {
              /AttributeConnID/ { connidtext = $0; }
              /AttributeThisDN / { thisdntext = $2; } #space removes DNRole
         }

 inqueued == 1 {
             if($0~ /AttributeConnID/) { connidtext = $0; }
              if($0~/AttributeThisDN /) { thisdntext = $2; } #space removes DNRole
         }

 inqueued == 1 && /AttributeConnID/{connidtext = $0;}
 inqueued == 1 && /AttributeThisDN /{ thisdntext = $2; } #space removes DNRole

答案 1 :(得分:0)

awk由<condition> { <action> }段组成。在<action>中,您可以像使用ifwhile结构在C中一样指定条件。您还有其他一些问题,只需将脚本重新编写为:

BEGIN { 
   print "Log File Analysis Sequencing for", FILENAME
}

/message EventQueued/ { 
    inqueued=1
    print 
}

inqueued == 1 {
    if (/AttributeConnID/) { connidtext = $0 }
    if (/AttributeThisDN/) { thisdntext = $2 } #space removes DNRole
}

#if first chars are a timetamp we know we are out of queued text
/\@?[0-9]+:[0-9}+:[0-9]+/ {
     if (thisdntext != 0) {
         print connidtext
         print thisdntext
     }
     inqueued=connidtext=thisdntext="" 
}

我不知道这是否能做你想做的事,但至少在句法上是正确的。