I want to specify a range of time and count the weekdays within this range in bash. I found this snipped and edited it to print January and February in 2020:
#!/bin/bash
startdate=2020-01-01
enddate=2020-02-28
curr="$startdate"
while true; do
echo "$curr"
[ "$curr" \< "$enddate" ] || break
curr=$( date +%Y-%m-%d --date "$curr +1 day" )
done
Now I only want to print all Mondays within this range, how can I do this?
I though of replacing echo "$curr" by something like: echo "$curr" | date +%Y-%m-%d-%a or without echo like: date +%Y-%m-%d-%a <<< "$curr" to add the weekdays to the output with %a and then filter the Mondays with sed or awk and count them. Though my approach of formatting the output this way does not work.