Date increment

hi Friends,

Today_Dt=`date "+%Y-%m-%d"`

So the Today date is 2010-05-03

I have a file which has date values as below

2010-04-27
2010-04-02
2010-04-18
2010-04-28
2010-04-29
..

I need find out latest date from the file and I want to add all the dates that resides between latest date and today date. Atlast I should add today date also in the file.

So the output file should be like

2010-04-02
2010-04-18
2010-04-27
2010-04-28
2010-04-29
2010-04-30
2010-05-01
2010-05-02
2010-05-03

any idea friends ?

Take a look at this thread Yesterdays Date/Date Arithmetic

Jean-Pierre.

---------- Post updated at 14:11 ---------- Previous update was at 13:47 ----------

A solution using datecalc :

#!/usr/bin/ksh

dateFile=gopal.txt

jLast=$( datecalc -j $( sed -n '$s/-/ /gp' ${dateFile} ) )
jToday=$( datecalc -j $( date +'%Y %m %d' ) )

while (( jLast < jToday ))
do
   (( jLast += 1 ))
   printf "%4d-%02d-%02d\n" $(datecalc -j ${jLast})
done >> ${dateFile}

Input file:

2010-04-27
2010-04-02
2010-04-18
2010-04-28
2010-04-29

Output file:

2010-04-27
2010-04-02
2010-04-18
2010-04-28
2010-04-29
2010-04-30
2010-05-01
2010-05-02
2010-05-03

Jean-Pierre.