Parsing errors in awk blocks

后端 未结 1 537
一个人的身影
一个人的身影 2021-01-25 10:03
awk \'BEGIN 
    { 
    INPUTFILE =\'XXX\'; iterator =0;
    requestIterator =0;
    storageFlag =T;
    printFlag =F;
    currentIteration =F;
    recordCount =1;
              


        
相关标签:
1条回答
  • 2021-01-25 10:17

    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.

    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; ... '
    

    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; ... '
    

    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 !!

    0 讨论(0)
提交回复
热议问题