Given a date in format 20130522, I need to generate a sequence of date+hour as below:
2013052112,2013052113,2013052114,...,2013052122,2013052123, 2013052200,2013052201,2013052202,...,2013052222,2013052223, 2013052300 in which the first date+hour is 12 hours before the given date and the last date+hour is the midnight in the next day of the given date.
I tried several ways but none of them is ideal. How to generate such a sequence in a clean way using shell script? Thanks!
--Edit--
Per your request, this is what I have so far:
day=20130522 begin=`date --date "$day -12 hours"` begin=`date -d "${begin:0:8} ${begin:8:2}" +%s` end=`date --date "$day +1 day"` end=`date -d "${end:0:8} ${end:8:2}" +%s` datestr=`date -d @${begin} +%Y%m%d%H` let begin=$begin+3600 while [ $begin -le $end ] do hr=`date -d @${begin} +%Y%m%d%H` datestr="$datestr,$hr" let begin=$begin+3600 done and this is what I got from above:
2013052100,2013052101,2013052102,...,2013052123, 2013052200,2013052201,2013052202,...,2013052223, 2013052300