Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple script for getting markdown files in a certain date range (assuming the files use a common Zettelkasten naming convention in which every file starts with YYYY-MM-DD).
#!/bin/bash
src=.
start=$1
end=$2
if [[ ! $start ]] && [[ ! $end ]]; then
printf "Usage: ./tools/get-entries-in-date-range.sh [start string] [end string]\nEnd string is optional.\n\nExample: To get filenames that come after 2020-03 (anywhere in March) but before 2020-03-29 (assuming files follow this naming convention):\n./tools/get-entries-in-date-range.sh 2020-03 2020-03-29\n";
exit 1;
fi
if [[ ! $end ]]; then
end=9999-99-99
fi
for file in ${src}/*.md
do
filename="${file##*/}"
if [[ "$filename" > "$start" ]] && [[ "$filename" < "$end" ]]; then
echo "$filename"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.