On this one, which I use every once in a while to count the amount of notes per year, Lyse came up with a much more streamlined solution. Thanks, mate!
(for file in *.md; do \
grep --max-count=1 'date:' "$file" | \
sed 's/date.*\([[:digit:]]\{4\}\).*/\1/'; \
done) | sort | uniq -c
hugo tech