I have list of week numbers extracted from huge log file, they were extracted using syntax:
$ date --date="Wed Mar 20 10:19:56 2012" +%W;
12
I want to create a simple bash function which can convert these week numbers to a date range. I suppose function should accept 2 arguments: $number and $year, example:
$ week() { ......... }
$ number=12; year=2012
$ week $number $year
"Mon Mar 19 2012" - "Sun Mar 25 2012"
Monday is the first day of week, ISO week numbers:
Output:
With
GNU date
:If anybody needs it: I found an even shorter way (not sure if easier):
I take the first day of the year and go n weeks forward to be somewhere in the right week. Then I take my weekday and go back/forward to reach monday and sunday.
If the start of a week is Sunday, you can use this version of weekof: