Nawk if logic problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Nawk if logic problem
# 1  
Old 06-26-2013
Nawk if logic problem

Code:
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}

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

AUDIT3c looks like this:
HTML Code:
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
# 2  
Old 06-26-2013
I hope your return key is not broken. If not, can you please indent your nawk code?
# 3  
Old 06-26-2013
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
# 4  
Old 06-26-2013
Quote:
Originally Posted by wawa
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.
This User Gave Thanks to Yoda For This Post:
# 5  
Old 06-26-2013
Nawk if logic problem

HTML Code:
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
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

2. Shell Programming and Scripting

problem in redirecting records using nawk

I am trying to redirect record to two files using nawk if-else. #Identify good and bad records and redirect records using if-then-else nawk -F"|" '{if(NF!=14){printf("%s\n",$0) >> "$fn"_bad_data}else{printf("%s\n",$0) >> $fn}}' "$fn".orig "$fn".orig is the source file name bad... (7 Replies)
Discussion started by: siteregsam
7 Replies

3. UNIX for Dummies Questions & Answers

if then else logic with while loop problem

Hi Friends, I have to do write a shell file based on one flag.If that flag value is 'N' then process look in $DATA are and the normal process continue.If vaule is 'P' then it check for the files in different location $CONV and move those file in $DATA area and rest of the process... (2 Replies)
Discussion started by: Param0073
2 Replies

4. Shell Programming and Scripting

Multiple array problem in NAWK

I HAD these 2 files: file1 pictures.txt 5 ref2313 4 ref2345 3 ref5432 2 ref4244 1 dance.txt 6 ref2342 5 ref2352 4 ref0695 3 ref5738 2 ref4948 1 treehouse.txt 6 ref8573 5 ref3284 4 ref5838 3 ref4738 2 ref4573 1 file2 pictures.txt 1 3 dance.txt 2 4 treehouse.txt 3 5 what I... (1 Reply)
Discussion started by: linuxkid
1 Replies

5. Shell Programming and Scripting

Please help me to figure out the logic for this problem

Hello, i am on 2.6.13-1.1526_FC4smp i have directory named /home , and in there i have directory 2009_10_10 and two files : 2009_10_10.log and 2009_10_11.log How to write shell script which will delete only file/s that don't have his/their 'parent' directory, so in this case , only... (7 Replies)
Discussion started by: tonijel
7 Replies

6. Shell Programming and Scripting

Problem with if logic

Hi there, In my shell program I have two if statements the first one checks that the date in yyyymm format is equal to a date from the parameter file in yyyymm format, and that the file and sends an appropiate email The second one checks that the date in yyyymm format is equal to a... (1 Reply)
Discussion started by: rjsha1
1 Replies

7. Shell Programming and Scripting

nawk problem

How are ya, Heres the problem. I have a line of data that can either be in this format. "20" or "20kg" for the 20kg one i need to be able to read that their is kg on the end of this field and then ignore it and move on to the next line. Can anyone help. Cheers (3 Replies)
Discussion started by: ben_shark
3 Replies
Login or Register to Ask a Question