For looping over dates, simply define start and end and loop over all desired time steps.
Just use epoch time for start and end and add 60 seconds or the desired step size at each iteration. Then set output format as desired.
#!/bin/bash
start=$(date -d2019-11-10T23:30 +%s)
end=$(date -d2019-11-11T02:00 +%s)
ddate="$start"
while [ $ddate -le $end ] ; do
date -d@"$ddate" +%Y%m%d_%H%M
ddate=$((ddate+60))
done
If you want to convert your date strings to a readable format for the date
command, just use sed
:
echo 20191110_2030 | sed 's/\(....\)\(..\)\(..\)_\(..\)\(..\)/\1-\2-\3T\4:\5/'
Unfortunately most date
-versions don't support defining the input string format.
20191110_{2330..2359} 20191111_{0000..0200}
– steeldriver Nov 10 '19 at 22:48find /some/dir -newermt "2019-11-10-T23:30:00" -not -newermt "2019-11-11-T02:00:00"
? (Replace/some/dir
by the dir you are interested in). If needed sed or perl can be used to convert the format. – Garo Nov 10 '19 at 23:15