Need help in genrating the logic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in genrating the logic
# 1  
Old 11-07-2006
Need help in genrating the logic

Hi,

I am little new to unix programming. I need some help in the program I am working on. I am looking for some effective way to do this. I have few file process something like below:

FLAG=0
$Process_Date="20060631"


. $COM/cat.ksh inquire file1 dat
if (( $? == 0 ))
then
export Emm1=$Hfile1
export Emm1_DATE=$HDate1

else
exit 1
fi


. $COM/cat.ksh inquire file2 txt
if (( $? == 0 ))
then
export Emm2=$Hfile2
export Emm2_DATE=$HDate2

else
exit 1
fi


. $COM/cat.ksh inquire file3 doc
if (( $? == 0 ))
then
export Emm3=$Hfile3
export Emm3_DATE=$HDate3

else
exit 1
fi


. $COM/cat.ksh inquire file4 doc
if (( $? == 0 ))
then
export Emm4=$Hfile4
export Emm4_DATE=$HDate4

else
exit 1
fi

and so on.....there are few more process like this....

Once the filename is passed in the cat.sh it generates a date for that particular file($HDate) as show above in bold. All I am trying to do is, if the $HDate for a file is not equal to the $Process_Date put a FLAG=1 for that file and in the end of the script I need to print all the files whose $HDate did not match with the $Process_Date and abort the script.

For example in above script let say for file1 and file2 the $HDate did not match with the $Process_Date, I still want the script to run till the end and compare the HDates for other files like file3 and file 4 and in the end once all the files are checked for the dates, I want to print the files whose dates did not match and abort.

I will really appreciate your help and advice in this regards.

Thanks
Amit
# 2  
Old 11-07-2006
Will appreciate any help or ideas on this......
# 3  
Old 11-07-2006
Could you just put what you want in a sentence or two. Your code is so, um, bad that it's misleading.
Questions:
when do you want to abort - at first error? or do you want all bad files?
It looks like you want a list of bad files with bad dates
# 4  
Old 11-07-2006
Thanks Jim for replying. I am sorry for not being very clear. Also I have simplified my code and added few lines.

All I am trying to do is to print all the files that has bad dates(mismatched dates) and then abort. I don't want to abort after first bad date.
Also if there are no bad dates then I don't want to abort.


/* Declare variables */
FLAG=0
$Process_Date="20060630"

/* we generate the date using our inhouse script cat.ksh for file1. The date will be in a variable $HDate1....This part is working fine*/

cat.ksh file1

## compare the date with process date if it does not match then it is a bad date.
if (($Process_Date == $HDate1)) then /* this checks for bad dates */
do something
else
FLAG =1
fi


/* we generate the date using our inhouse script cat.ksh for file2. The date will be in a variable $HDate2 ...This part is working fine*/

cat.ksh file2

## compare the date with process date if it does not match then it is a bad date.

if (($Process_Date == $HDate2)) then
do something
else
FLAG =1
fi


Thanks
Amit

Last edited by amitjha; 11-07-2006 at 04:52 PM..
# 5  
Old 11-07-2006
ok.
Code:
#!/bin/ksh
/* Declare variables */
FLAG=0
Process_Date="20060630"
badfile=""       

# process all the files in one loop

for file in file1.txt file2.txt file3.txt file4.txt  
do
   cat.ksh $file 
   if [[ "$Process_Date" = "$HDate1" ]] ;  then 
       echo "$file is okay"  
   else
       FLAG=1
       badfile=$badfile" $file"
   fi
done

if [[ FLAG -eq 1 ]] ; then        # exit early with message
   echo "bad files found: $badfile"
   exit 1
fi
# continue script....

# 6  
Old 11-07-2006
Thanks Jim for the quick reply. Your logic does help. Is there a way I can print the bad files one below another rather than in a straight line. I mean, Is there a new line character like "\n" in unix.

Thanks
Amit
# 7  
Old 11-08-2006
Code:
   else
       FLAG=1
       badfile=$badfile "\n$file"
   fi

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

genrating pseudo random numbers

I want to generate the file in following format -------------------------------------- mov t1, %r1 mov t2, %g1 mov t3, %o1 . . . . m times add %r1, %g1, %o1 add %r2, %g2, %o2 . . . n times ------------------------------------------- (7 Replies)
Discussion started by: hack_tom
7 Replies
Login or Register to Ask a Question