0

I am trying to create a series of dates from 01/01/2010 to 01/02/2010 with the minutes at uneven distances, like so:

2010  1  1  00  00  00
2010  1  1  00  20  00
2010  1  1  00  30  00
2010  1  1  00  40  00
2010  1  1  01  00  00
2010  1  1  01  20  00
2010  1  1  01  30  00
2010  1  1  01  40  00

...
2010  2  1  00  00  00

So at minute 00, minute 20, minute 30 and minute 40, every hour until the end date. I have found help in question https://stackoverflow.com/questions/15621409/print-dates-in-date-range-linux But I am unable to add minutes to it, let alone spaces instead of '-' and the uneven steps. This is my code so far, which does not work:

startdate=2010-01-01-00-00-00
enddate=2010-02-01-00-00-00

curr="$startdate"
while true; do
    echo "$curr"
    [ "$curr" \< "$enddate" ] || break
    curr=$( date +%Y-%m-%d-%H-%M-%S --date "$curr +10 minutes" )
done

How do I create the output above at those intervals with spaces inbetween?

0

Here is how I'd do it :

$ date -d '2010-01-01 00:00:00' +%s
1262300400
$ date -d '2010-02-01 00:00:00' +%s
1264978800

$ for timestamp in {1262300400..1264978800..600}; do date -d @"$timestamp" '+%Y %m %d %H %M %S'; done | grep -Ev '[15]0 00$'

What grep -Ev '[15]0 00$' does :

  • grep itself selects line(s) matching a set of conditions described by its parameters
  • -v : select lines that DO NOT match the parameters
  • -E : declares that the pattern we'll try to match is an 'Extended regular expression' (it was actually NOT required here - my mistake)
  • [15]0 00$ : a regular expression saying "select lines ending with "1 or 5" then "zero" then "space" then "double zero". This matches the "10" and "50" lines, which are removed thanks to the -v described above.
2
  • I still need to delete the minute 10 and minute 50. How do I do that? – Jellyse May 22 '19 at 14:28
  • @Jellyse Ooops, I missed that point in your question. I've just edited my answer. – Httqm May 22 '19 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.