在解析AWK块错误 [英] Parsing errors in awk blocks

查看:76
本文介绍了在解析AWK块错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

awk 'BEGIN 
    { 
    INPUTFILE ='XXX'; iterator =0;
    requestIterator =0;
    storageFlag =T;
    printFlag =F;
    currentIteration =F;
    recordCount =1;
       while (getline < "'"$INPUTFILE"'") 
       { 
             requestArray[requestIterator]++; 
             requestIterator++;
       }
     } 
     if ($1 ~ /RequestId/) 
     {  
            FS = "="; 
            if($2 in requestArray) 
            {
                  storage[iterator] =$0;
                  printFlag =T;
                  next
            }
            else 
            {
                  storageFlag =F;
                  next
            }
      }
      else 
      {
           if((storageFlag =='T' && $0 != "EOE"))   
           {
                storage[iterator]=$0; iterator++;
           } 
           else {if(storageFlag == 'F')
           {
                next
           } 
           else
           {
               if(printFlag == 'T')
               {
                    for(details in storage) 
               {
                    print storage[details] >> FILE1;
                    delete storage[details];
               } 
               printFlag =F;
               storageFlag =T;
               next
           }
     }'

我对着上面code一些语法错误。你脂肪酶能帮帮我吗?

I am facing some syntax error in the above code. Could you ppl please help me?

AWK:BEGIN {INPUTFILE = XXXX;迭代器= 0; requestIterator = 0; storageFlag = T; printFlag = F; currentIteration = F;总记录= 1;而(函数getline&LT;){requestArray [requestIterator] ++ ; requestIterator ++;}}如果($ 1〜/的requestId /){FS ==;如果(在requestArray $ 2){储存[迭代器] = $ 0; printFlag = T;接下来}其他{storageFlag = F;接下来}}其他{如果((storageFlag == T&放大器;&安培;!$ 0 = EOE)){储存[迭代器] = $ 0;迭代器++;}其他{如果(storageFlag == F){下一}其他{如果(printFlag == T) {为(存储信息){打印存储[详情] >> XXXX;删除存储[详情];} printFlag = F; storageFlag = T;接下来}}}}

awk: BEGIN{INPUTFILE =XXXX;iterator =0;requestIterator =0;storageFlag =T;printFlag =F;currentIteration =F;recordCount =1;while (getline < ""){requestArray[requestIterator]++;requestIterator++;}}if ($1 ~ /RequestId/){FS = "=";if($2 in requestArray){storage[iterator] =$0;printFlag =T;next}else{storageFlag =F;next}}else{if((storageFlag ==T && $0 != EOE)){storage[iterator]=$0;iterator++;}else{if(storageFlag == F){next}else{if(printFlag == T){for(details in storage){print storage[details] >> XXXX;delete storage[details];}printFlag = F;storageFlag =T;next}}}}

AWK:^语法错误

AWK:^语法错误

推荐答案

行情都是问题。在 INPUTFILE ='XXX'的第一个单引号将被解析为匹配一个之前就开始,并且从那时起所有解析坏了。

Quotes are the problem. The first single quotes on INPUTFILE ='XXX' is going to be parsed as matching the one before BEGIN, and from then on all the parsing is broken.

要么逃避报价或只是把AWK文件转换成一个单独的文件,而不是内联。

Either escape the quotes or just put the awk file into a seperate file rather than "inline".

# STARTING POINT - known bad
awk 'BEGIN { INPUTFILE ='XXX'; iterator =0; ... '

已被改写,以消除所有的单引号外对内

Has to be rewritten to remove all of the single quotes inside the outer pair

 awk 'BEGIN { INPUTFILE ="XXX"; iterator =0; ... '

或取决于是否需要双打或单打,双打使用外单内。

Or depending on if you need doubles or singles, use doubles outside and single inside

awk "BEGIN { INPUTFILE ='XXX'; iterator =0; ... '

或逃避单打报价让他们撑过到awk和不要被壳食用。

or escape the singles quotes so they make it through to awk and don't get consumed by the shell.

awk 'BEGIN { INPUTFILE =\'XXX\'; iterator =0; ... '

您所有的问题消失,如果你把awk脚本到一个单独的文件,而不是它内联外壳。你可以有任何引用你喜欢,没有人会在意!

All of your problems go away if you put the awk script into a separate file rather than inlining it the shell. You can have whatever quotes you like and no one will care !!

这篇关于在解析AWK块错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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