Created
April 16, 2023 19:57
-
-
Save alexander-potemkin/9ceb1a72f925be7176416d609da5ca4f to your computer and use it in GitHub Desktop.
Converts files names from Agenda app to Obsidian 'Daily notes' format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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