RE: date format in ksh
Thanks Kirti for the reply and all others which took the time/ effort to respond. Regards Suhen Suhen, If all you want is a format check (and no date validation) here is a way to do it: #!/usr/bin/ksh REQD=ZZ-ZZZ-ZZ RCVD=`echo $1| tr '[A-Z] | [a-z] | [0-9]' '[Z*]'` if [ $REQD = $RCVD ] then echo "Input Format is Okay" else echo "Input Format is WRONG" fi HTH, Regards, - Kirti Deshpande Verizon Information Services http://www.superpages.com > -Original Message- > From: Suhen Pather [SMTP:[EMAIL PROTECTED]] > Sent: Friday, October 26, 2001 7:40 PM > To: Multiple recipients of list ORACLE-L > Subject: RE: date format in ksh > > Jared, > > Thanks for the reply. > I am passing a hardcoded date. > I am not getting a date from the > "date" command in ksh. > > What my ksh does is retrieves $1 and must check if the date format > is in DD-MON-YY eg. 02-FEB-01. > It uses the hardcoded date (passed in as argument 1) in the script. > If the date is in another format other than above then it must exit. > > Regards > Suhen > > > > > > date +%d-%b-%Y > > man date. > > You may have to look at the man page on a system with more > recent documentation, such as linux. The man page on > Solaris is incomplete. > > JARed > > > > > > > Suhen Pather > > recipients > of list ORACLE-L <[EMAIL PROTECTED]> > gs.com.au> cc: > > Sent by: Subject: date format > in > ksh > [EMAIL PROTECTED] > > > > > > 10/25/01 08:00 PM > > Please respond to > > ORACLE-L > > > > > > > > > > List, > > > > > > Sorry to deviate from the topic, but > > > I am writing a korn shell script that would exit if the date format is > > > incorrect. > > > > > > I just need something to compare the date format passed in with > DD-MON-. > > > > > > Eg. > > > I am passing an argument to my ksh script being the date. > > > If the date is in any other format but DD-MON- the ksh must exit. > > > > > > Eg. sh test.ksh 02/05/1999 > > > > > > It must exit. > > > > > > The only format excepted should be > > > sh test.ksh 02-MON- > > > > > > TIA > > > > > > Regards > > > Suhen > > > > > > > > > > > > > -- > Please see the official ORACLE-L FAQ: http://www.orafaq.com > -- > Author: Suhen Pather > INET: [EMAIL PROTECTED] > > Fat City Network Services-- (858) 538-5051 FAX: (858) 538-5051 > San Diego, California-- Public Internet access / Mailing Lists > > To REMOVE yourself from this mailing list, send an E-Mail message > to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in > the message BODY, include a line containing: UNSUB ORACLE-L > (or the name of mailing list you want to be removed from). You may > also send the HELP command for other information (like subscribing). -- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Deshpande, Kirti INET: [EMAIL PROTECTED] Fat City Network Services-- (858) 538-5051 FAX: (858) 538-5051 San Diego, California-- Public Internet access / Mailing Lists To REMOVE yourself from this mailing list, send an E-Mail message to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). -- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Suhen Pather INET: [EMAIL PROTECTED] Fat City Network Services-- (858) 538-5051 FAX: (858) 538-5051 San Diego, California-- Public Internet access / Mailing Lists To REMOVE yourself from this mailing list, send an E-Mail message to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
RE: date format in ksh
Use the /usr/sadm/bin/valdate command and check the return status. Examples: --GOOD DATE-- 12322:oracle@e6500a> valdate -f "%e-%b-%Y" 1-jan-200112322:oracle@e6500a> echo $?0 --BAD DATE-- 12322:oracle@e6500a> valdate -f "%e-%b-%Y" 41-JaN-200112322:oracle@e6500a> echo $?1 The valdate command doesn't seam to like leading 0's (zero's) so you can just use sed to strip it off. This example should do most of what ya need: 12322:oracle@e6500a> cat dateck.ksh#!/bin/ksh vDATE="${1}"if valdate -f "%e-%b-%Y" $(echo "${vDATE}" | sed "s/^0//")then echo "Good date ${vDATE}"else echo "Bad date ${vDATE}"fi 12322:oracle@e6500a> dateck.ksh 41-mar-2001Bad date 41-mar-200112322:oracle@e6500a> dateck.ksh 01-Mar-2001Good date 01-Mar-2001 -Original Message-From: Suhen Pather [mailto:[EMAIL PROTECTED]]Sent: Thursday, October 25, 2001 8:00 PMTo: Multiple recipients of list ORACLE-LSubject: date format in ksh List, Sorry to deviate from the topic, but I am writing a korn shell script that would exit if the date format is incorrect. I just need something to compare the date format passed in with DD-MON-. Eg. I am passing an argument to my ksh script being the date. If the date is in any other format but DD-MON- the ksh must exit. Eg. sh test.ksh 02/05/1999 It must exit. The only format excepted should be sh test.ksh 02-MON- TIA Regards Suhen
Re: date format in ksh
Jacques, You could have learned Perl in the time it took to write that. :) Jared On Friday 26 October 2001 20:20, Jacques Kilchoer wrote: > > -Original Message- > > From: Suhen Pather [mailto:[EMAIL PROTECTED]] > > > > Thanks for the reply. > > I am passing a hardcoded date. > > I am not getting a date from the > > "date" command in ksh. > > > > What my ksh does is retrieves $1 and must check if the date format > > is in DD-MON-YY eg. 02-FEB-01. > > It uses the hardcoded date (passed in as argument 1) in the script. > > If the date is in another format other than above then it must exit. > > I dusted off my old C programming skills (Sorry Mr. Still I still don't > know PERL that well). Why not write a "check_date" program that returns 0 > for a valid date and 1 for an invalid date? > The date verification function is case-sensitive and only checks for the > one format. It also assumes that two-digit years will be prefixed with > "20". Modifying it to be more user-friendly is left as an exercise to the > alert reader. > > /* > * verify that date passed to function is a correct date > * parameter passed to function must be in the same format > * as shell command <> > * example: check_date 26-Jan-01 > *echo $? > *check_date 32-Jan-01 > *echo $? > * > * program assumes that %b date format will return a string with 3 > characters > */ > #include > #include > #include > #include > #include > > > #define B_DTFMT_LEN 3 > #define DT_LEN 6 + B_DTFMT_LEN > #define HIGH_MM 11 > #define CBASE_YEAR 1900 > #define BASE_YEAR 2000 > > extern int main (int argc, char **argv) > { >short int mm ; >struct tm tmi ; >time_t t ; >char month[B_DTFMT_LEN + 1] = { '\0' }, > day[3] = { '\0' }, > compmonth[B_DTFMT_LEN + 1] = { '\0' }, > compdate[DT_LEN + 1] = { '\0' } ; > >if (argc != 2) >{ > puts ("Usage - check_date \"date\" (date in %d-%b-%y format)") ; > return EXIT_SUCCESS ; >} > >if (strlen (argv[1]) != DT_LEN || argv[1][2] != '-' > >|| argv[1][3 + B_DTFMT_LEN] != '-' >|| ! isdigit (argv[1][0]) || ! isdigit (argv[1][1]) >|| ! isdigit (argv[1][4 + B_DTFMT_LEN]) >|| ! isdigit (argv[1][5 + B_DTFMT_LEN]) ) > > return EXIT_FAILURE ; > >strncpy (month, argv[1] + 3, B_DTFMT_LEN) ; > >memset (&tmi, '\0', sizeof tmi) ; >mm = -1 ; >while (strncmp (month, compmonth, B_DTFMT_LEN) && ++mm <= HIGH_MM) >{ > tmi.tm_mday = 1 ; > tmi.tm_mon = mm ; > tmi.tm_year = 2001 ; > strftime (compmonth, B_DTFMT_LEN + 1, "%b", &tmi) ; >} >if (mm > HIGH_MM) > return EXIT_FAILURE ; > >strncpy (day, argv[1], 2) ; >tmi.tm_mday = atoi (day) ; >tmi.tm_mon = mm ; >tmi.tm_year = BASE_YEAR + atoi (argv[1] + 4 + B_DTFMT_LEN) - CBASE_YEAR > ; if ((t = mktime (&tmi)) == (time_t) -1) > return EXIT_FAILURE ; > >tmi = *localtime (&t) ; >strftime (compdate, DT_LEN + 1, "%d-%b-%y", &tmi) ; >if (strcmp (argv[1], compdate)) > return EXIT_FAILURE ; > >return EXIT_SUCCESS ; > } Content-Type: text/html; charset="iso-8859-1"; name="Attachment: 1" Content-Transfer-Encoding: quoted-printable Content-Description: -- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Jared Still INET: [EMAIL PROTECTED] Fat City Network Services-- (858) 538-5051 FAX: (858) 538-5051 San Diego, California-- Public Internet access / Mailing Lists To REMOVE yourself from this mailing list, send an E-Mail message to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
RE: date format in ksh
Suhen, If all you want is a format check (and no date validation) here is a way to do it: #!/usr/bin/ksh REQD=ZZ-ZZZ-ZZ RCVD=`echo $1| tr '[A-Z] | [a-z] | [0-9]' '[Z*]'` if [ $REQD = $RCVD ] then echo "Input Format is Okay" else echo "Input Format is WRONG" fi HTH, Regards, - Kirti Deshpande Verizon Information Services http://www.superpages.com > -Original Message- > From: Suhen Pather [SMTP:[EMAIL PROTECTED]] > Sent: Friday, October 26, 2001 7:40 PM > To: Multiple recipients of list ORACLE-L > Subject: RE: date format in ksh > > Jared, > > Thanks for the reply. > I am passing a hardcoded date. > I am not getting a date from the > "date" command in ksh. > > What my ksh does is retrieves $1 and must check if the date format > is in DD-MON-YY eg. 02-FEB-01. > It uses the hardcoded date (passed in as argument 1) in the script. > If the date is in another format other than above then it must exit. > > Regards > Suhen > > > > > > date +%d-%b-%Y > > man date. > > You may have to look at the man page on a system with more > recent documentation, such as linux. The man page on > Solaris is incomplete. > > JARed > > > > > > > Suhen Pather > > recipients > of list ORACLE-L <[EMAIL PROTECTED]> > gs.com.au> cc: > > Sent by: Subject: date format > in > ksh > [EMAIL PROTECTED] > > > > > > 10/25/01 08:00 PM > > Please respond to > > ORACLE-L > > > > > > > > > > List, > > > > > > Sorry to deviate from the topic, but > > > I am writing a korn shell script that would exit if the date format is > > > incorrect. > > > > > > I just need something to compare the date format passed in with > DD-MON-. > > > > > > Eg. > > > I am passing an argument to my ksh script being the date. > > > If the date is in any other format but DD-MON- the ksh must exit. > > > > > > Eg. sh test.ksh 02/05/1999 > > > > > > It must exit. > > > > > > The only format excepted should be > > > sh test.ksh 02-MON- > > > > > > TIA > > > > > > Regards > > > Suhen > > > > > > > > > > > > > -- > Please see the official ORACLE-L FAQ: http://www.orafaq.com > -- > Author: Suhen Pather > INET: [EMAIL PROTECTED] > > Fat City Network Services-- (858) 538-5051 FAX: (858) 538-5051 > San Diego, California-- Public Internet access / Mailing Lists > > To REMOVE yourself from this mailing list, send an E-Mail message > to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in > the message BODY, include a line containing: UNSUB ORACLE-L > (or the name of mailing list you want to be removed from). You may > also send the HELP command for other information (like subscribing). -- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Deshpande, Kirti INET: [EMAIL PROTECTED] Fat City Network Services-- (858) 538-5051 FAX: (858) 538-5051 San Diego, California-- Public Internet access / Mailing Lists To REMOVE yourself from this mailing list, send an E-Mail message to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
RE: date format in ksh
Title: RE: date format in ksh > -Original Message- > From: Suhen Pather [mailto:[EMAIL PROTECTED]] > > Thanks for the reply. > I am passing a hardcoded date. > I am not getting a date from the > "date" command in ksh. > > What my ksh does is retrieves $1 and must check if the date format > is in DD-MON-YY eg. 02-FEB-01. > It uses the hardcoded date (passed in as argument 1) in the script. > If the date is in another format other than above then it must exit. I dusted off my old C programming skills (Sorry Mr. Still I still don't know PERL that well). Why not write a "check_date" program that returns 0 for a valid date and 1 for an invalid date? The date verification function is case-sensitive and only checks for the one format. It also assumes that two-digit years will be prefixed with "20". Modifying it to be more user-friendly is left as an exercise to the alert reader. /* * verify that date passed to function is a correct date * parameter passed to function must be in the same format * as shell command <> * example: check_date 26-Jan-01 * echo $? * check_date 32-Jan-01 * echo $? * * program assumes that %b date format will return a string with 3 characters */ #include #include #include #include #include #define B_DTFMT_LEN 3 #define DT_LEN 6 + B_DTFMT_LEN #define HIGH_MM 11 #define CBASE_YEAR 1900 #define BASE_YEAR 2000 extern int main (int argc, char **argv) { short int mm ; struct tm tmi ; time_t t ; char month[B_DTFMT_LEN + 1] = { '\0' }, day[3] = { '\0' }, compmonth[B_DTFMT_LEN + 1] = { '\0' }, compdate[DT_LEN + 1] = { '\0' } ; if (argc != 2) { puts ("Usage - check_date \"date\" (date in %d-%b-%y format)") ; return EXIT_SUCCESS ; } if (strlen (argv[1]) != DT_LEN || argv[1][2] != '-' || argv[1][3 + B_DTFMT_LEN] != '-' || ! isdigit (argv[1][0]) || ! isdigit (argv[1][1]) || ! isdigit (argv[1][4 + B_DTFMT_LEN]) || ! isdigit (argv[1][5 + B_DTFMT_LEN]) ) return EXIT_FAILURE ; strncpy (month, argv[1] + 3, B_DTFMT_LEN) ; memset (&tmi, '\0', sizeof tmi) ; mm = -1 ; while (strncmp (month, compmonth, B_DTFMT_LEN) && ++mm <= HIGH_MM) { tmi.tm_mday = 1 ; tmi.tm_mon = mm ; tmi.tm_year = 2001 ; strftime (compmonth, B_DTFMT_LEN + 1, "%b", &tmi) ; } if (mm > HIGH_MM) return EXIT_FAILURE ; strncpy (day, argv[1], 2) ; tmi.tm_mday = atoi (day) ; tmi.tm_mon = mm ; tmi.tm_year = BASE_YEAR + atoi (argv[1] + 4 + B_DTFMT_LEN) - CBASE_YEAR ; if ((t = mktime (&tmi)) == (time_t) -1) return EXIT_FAILURE ; tmi = *localtime (&t) ; strftime (compdate, DT_LEN + 1, "%d-%b-%y", &tmi) ; if (strcmp (argv[1], compdate)) return EXIT_FAILURE ; return EXIT_SUCCESS ; }
RE: date format in ksh
Jared, Thanks for the reply. I am passing a hardcoded date. I am not getting a date from the "date" command in ksh. What my ksh does is retrieves $1 and must check if the date format is in DD-MON-YY eg. 02-FEB-01. It uses the hardcoded date (passed in as argument 1) in the script. If the date is in another format other than above then it must exit. Regards Suhen date +%d-%b-%Y man date. You may have to look at the man page on a system with more recent documentation, such as linux. The man page on Solaris is incomplete. JARed Suhen Pather gs.com.au> cc: Sent by: Subject: date format in ksh [EMAIL PROTECTED] 10/25/01 08:00 PM Please respond to ORACLE-L List, Sorry to deviate from the topic, but I am writing a korn shell script that would exit if the date format is incorrect. I just need something to compare the date format passed in with DD-MON-. Eg. I am passing an argument to my ksh script being the date. If the date is in any other format but DD-MON- the ksh must exit. Eg. sh test.ksh 02/05/1999 It must exit. The only format excepted should be sh test.ksh 02-MON- TIA Regards Suhen -- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Suhen Pather INET: [EMAIL PROTECTED] Fat City Network Services-- (858) 538-5051 FAX: (858) 538-5051 San Diego, California-- Public Internet access / Mailing Lists To REMOVE yourself from this mailing list, send an E-Mail message to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
Re: date format in ksh
date +%d-%b-%Y man date. You may have to look at the man page on a system with more recent documentation, such as linux. The man page on Solaris is incomplete. JARed Suhen Pather gs.com.au> cc: Sent by: Subject: date format in ksh [EMAIL PROTECTED] 10/25/01 08:00 PM Please respond to ORACLE-L List, Sorry to deviate from the topic, but I am writing a korn shell script that would exit if the date format is incorrect. I just need something to compare the date format passed in with DD-MON-. Eg. I am passing an argument to my ksh script being the date. If the date is in any other format but DD-MON- the ksh must exit. Eg. sh test.ksh 02/05/1999 It must exit. The only format excepted should be sh test.ksh 02-MON- TIA Regards Suhen -- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: INET: [EMAIL PROTECTED] Fat City Network Services-- (858) 538-5051 FAX: (858) 538-5051 San Diego, California-- Public Internet access / Mailing Lists To REMOVE yourself from this mailing list, send an E-Mail message to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).