The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-07-2006
amitjha amitjha is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 4
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 (permalink)  
Old 11-07-2006
amitjha amitjha is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 4
Will appreciate any help or ideas on this......
  #3 (permalink)  
Old 11-07-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,754
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 (permalink)  
Old 11-07-2006
amitjha amitjha is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 4
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 (permalink)  
Old 11-07-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,754
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 (permalink)  
Old 11-07-2006
amitjha amitjha is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 4
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0