Skip to content

Instantly share code, notes, and snippets.

@jimkang
Last active April 5, 2020 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimkang/1c4c9e44fe4133c8c3159572858bf0e3 to your computer and use it in GitHub Desktop.
Save jimkang/1c4c9e44fe4133c8c3159572858bf0e3 to your computer and use it in GitHub Desktop.
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