Skip to content

Instantly share code, notes, and snippets.

@alexander-potemkin
Created April 16, 2023 19:57
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 alexander-potemkin/9ceb1a72f925be7176416d609da5ca4f to your computer and use it in GitHub Desktop.
Save alexander-potemkin/9ceb1a72f925be7176416d609da5ca4f to your computer and use it in GitHub Desktop.
Converts files names from Agenda app to Obsidian 'Daily notes' format
#!/bin/bash
# Loop through each file in the current directory
for file in *.md
do
# Check if the file name matches the pattern "D MM YYYY"
if [[ $file =~ ^([0-9]{1,2})\ ([A-Za-z]{3})\ ([0-9]{4})\.md$ ]]
then
# Extract the day, month, and year from the file name
day=${BASH_REMATCH[1]}
month=${BASH_REMATCH[2]}
year=${BASH_REMATCH[3]}
# Convert the month abbreviation to a numeric value
case $month in
"Jan") month="01";;
"Feb") month="02";;
"Mar") month="03";;
"Apr") month="04";;
"May") month="05";;
"Jun") month="06";;
"Jul") month="07";;
"Aug") month="08";;
"Sep") month="09";;
"Oct") month="10";;
"Nov") month="11";;
"Dec") month="12";;
esac
# Add a leading zero to day if it's a single digit
if [ ${#day} -eq 1 ]
then
day="0${day}"
fi
# Rename the file with the new format "YYYY-MM-DD"
new_name="${year}-${month}-${day}.md"
mv "$file" "$new_name"
echo "$file => $new_name"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment