![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| cannot get logic for concatenation awk | user_prady | Shell Programming and Scripting | 7 | 12-10-2007 03:09 AM |
| If Then Else Logic | jadionne | UNIX for Dummies Questions & Answers | 7 | 11-23-2007 04:27 AM |
| cannot get the logic | dineshr85 | Shell Programming and Scripting | 3 | 10-11-2007 07:34 AM |
| genrating pseudo random numbers | hack_tom | Shell Programming and Scripting | 7 | 04-27-2007 10:10 PM |
| what the logic | ramneek | IP Networking | 2 | 09-05-2005 07:42 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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.. |
|
||||
|
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....
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|