1

我有以下 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=""; 
     }
4

2 回答 2

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
于 2012-11-16T11:44:14.407 回答
0

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

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="" 
}

我不知道这是否会做你想要的,但至少在语法上是正确的。

于 2012-11-16T12:42:52.120 回答