Shell one liner to produce a delimited file with massive number of date ranges
A project I’m working required a comma delimited file containing date ranges, in one week increments, from July 1987 to the present. That’s 1166 week ranges. What sounds like a potentially time consuming ordeal, takes about 10 sec to produce with the following shell one liner:
for n in $(seq 0 1166); \ do echo -e \ $(date +%m/%d/%Y --date="1987-07-01 +$n week")","\ $(date +%m/%d/%Y --date="1987-07-01 +$n week +6 day") \ >> date.ranges; done
The result:
07/01/1987,07/07/1987 07/08/1987,07/14/1987 07/15/1987,07/21/1987 ... 10/21/2009,10/27/2009 10/28/2009,11/03/2009 11/04/2009,11/10/2009
Leave a comment