The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Building Full-Text Search Applications with Oracle Text iBot Oracle Updates (RSS) 0 04-06-2008 02:10 AM
how to find min, max dates in a file gemini106 Shell Programming and Scripting 6 03-16-2008 09:55 PM
Nemo file manager organizes around a calendar iBot UNIX and Linux RSS News 0 12-10-2007 08:40 AM
grep a log file between 2 dates Epiphone Shell Programming and Scripting 37 07-31-2007 01:20 PM
Formatting dates in a file maverick UNIX for Dummies Questions & Answers 6 12-18-2001 07:46 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-25-2002
Registered User
 

Join Date: Jan 2002
Posts: 10
Stumble this Post!
builind text file with calendar dates

Can somebody help me in building a text file which will contain the dates of 2 yrs in the format YYYYMMDD using korn shell

e.g. to generate a file with the contents

20010101
20010102
...
...
20010131
20010201
...
...
20010228
20010301
...

and so on.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-25-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,443
Stumble this Post!
Code:
#! /usr/bin/ksh

#              ja fe ma ap ma ju ju ag se oc no de
set -A lasts 0 31 28 31 30 31 30 31 31 30 31 30 31

typeset -Z2 dmonth dday

#
#  loop on years

year=2001
while ((year<2003)) ; do

#
#  is this a leap year?
        leap=0
        if ((!(year%100))); then
                ((!(year%400))) && leap=1
        else
                ((!(year%4))) && leap=1
        fi

#
#  set number of days in february
        lasts[2]=28
        ((leap)) && lasts[2]=29
#
#  loop on month
        month=1
        while ((month<13)); do

#
#  loop on day
                day=1
                while((day<(lasts[month])+1)) ; do
                        dday=$day 
                        dmonth=$month
                        echo ${year}${dmonth}${dday}
                        ((day=day+1))
                done
                ((month=month+1))
        done

        ((year=year+1))
done
exit 0
Reply With Quote
  #3 (permalink)  
Old 02-26-2002
Registered User
 

Join Date: Jan 2002
Posts: 10
Stumble this Post!
Thanks Perderabo !

It has worked well.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0