Nawk if logic problem

nawk '{ fmt="%3s %22s %48s %35s %21s\n"; if ($3==$6 && $1=="STOPLOSS") { tpy="Successful Match"; jnme=$1; sts="File will be loaded"; cntrl=$3; audit=$6; printf (fmt, tpy,jnme,sts,cntrl,audit) >> "'${AUDIT_DATA_FILE}/${AUDIT36}'" }else if ($3!=$6 && $1=="STOPLOSS") { tpy="Mis-Match            "; jnme=$1; sts="File will NOT be loaded"; cntrl=$3; audit=$6; printf (fmt, tpy,jnme,sts,cntrl,audit) >> "'${AUDIT_DATA_FILE}/${AUDIT36}'" }else if ($1=="NO_FILE") { jnme=$1; sts=$2; cntrl=$3; printf (fmt, jnme,sts,cntrl) >> "'${AUDIT_DATA_FILE}/${AUDIT36}'" } }' ${AUDIT_DATA_FILE}/${AUDIT3c}

[/CODE]

Can somebody tell me why I'm not getting any output in "'${AUDIT_DATA_FILE}/${AUDIT36}'".

AUDIT3c looks like this:

NO_FILE PREMIUM_STP.CTL_is_not_available_to_load.  No_File_will_load._***NO_FILE***

This nawk statement worked before I added the third �else if�, now I don't get any output

I hope your return key is not broken. If not, can you please indent your nawk code?

nawk '{ fmt="%3s %22s %48s %35s %21s\n";
             if ($3==$6 && $1=="STOPLOSS") {
                 tpy="Successful Match";
                 jnme=$1;
                 sts="File will be loaded";
                 cntrl=$3;
                 audit=$6;
                 printf (fmt, tpy,jnme,sts,cntrl,audit) >> "'${AUDIT_DATA_FILE}/${AUDIT36}'"
              }
              else if ($3!=$6 && $1=="STOPLOSS") {
                      tpy="Mis-Match            ";
                      jnme=$1;
                      sts="File will NOT be loaded";
                      cntrl=$3;
                      audit=$6;
                      printf (fmt, tpy,jnme,sts,cntrl,audit) >> "'${AUDIT_DATA_FILE}/${AUDIT36}'"
                    }
                    else if ($1=="NO_FILE") {
                    jnme=$1;
                    sts=$2;
                    cntrl=$3;
                    printf (fmt, jnme,sts,cntrl) >> "'${AUDIT_DATA_FILE}/${AUDIT36}'" } }' ${AUDIT_DATA_FILE}/${AUDIT3c}

I hope this helps

Yes indeed!

I noticed that you defined fmt="%3s %22s %48s %35s %21s\n" (5 params)

But in your last else if statement you are printing printf (fmt, jnme,sts,cntrl) (3 params)

I think you have to fix that.

1 Like
do you always have to have the same amount?  Is that what you mean by fix that?

---------- Post updated at 11:05 AM ---------- Previous update was at 11:04 AM ----------

nevermind how stupid