This is a small bash script I used to convert Roam Daily notes so they work with a YYYY-MM-DD format and add some front matter metadata to work better in Obsidian.
Note for MacOS Users
bashsed and date in this script assume a GNU userland. If you are on Linux it should just work. If you are on Mac OS X try brew install bash gnu-sed gnutls and make sure gnu seddate and bash are on your path.
Iâve not tried it with Mac OS Xâs BSD version of these.
Usage
As always, backup before trying this.
Note if youâve seeded an Obsidian vault with a Roam Research markdown export, make sure to close that vault before running this script. Obsidian observes changes in the vault folder and tries to update its indexes during the conversion which will slow things down.
From the root of a Roam Research markdown export run:
# convert all daily notes from 2020/2021
ls *,\ 202[01].md | convert_daily_notes
convert_daily_notes Script
#/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
roam_date_to_obsidian() {
date --date="$(echo "${*}" | sed 's/th//;s/nd//;s/rd//;s/1st/1/')" \
'+%Y-%m-%d'
}
while IFS= read -r line; do
roam_daily_note=${line/%.md/}
obsidian_daily_note=$(roam_date_to_obsidian ${roam_daily_note})
# add front matter
echo "---" >> ${obsidian_daily_note}.md
echo "tags: [daily]" >> ${obsidian_daily_note}.md
echo "---" >> ${obsidian_daily_note}.md
cat "${roam_daily_note}.md" >> ${obsidian_daily_note}.md
# update links
sed -i "s/\[\[${roam_daily_note}]]/[[${obsidian_daily_note}]]/g" *.md */*.md || true
# give it a relevant timestamp
touch -d ${obsidian_daily_note} ${obsidian_daily_note}.md
rm "${roam_daily_note}.md"
done
A complete newbie to both Obsidian and Bash scripts⌠Iâm using Windows 10, could you please point me in the right direction of how to put this together?
Can I simply cut and paste the code into Notepad and he invoke it from Command Prompt?!
Really sorry for the simplicity of this question - this solution looks perfect for my needs!!
OK - so Iâve made some headway with this (thanks to Google!)
Iâve installed Ubuntu from the Windows store and have created the âconvert_daily_notes.shâ file within the relevant vault using the nano editor.
I have then tried various versions to try and run the script:
As above
./ convert_daily_notes.sh
But Iâve had the following error returned
cat: .md: No such file or directory
Iâm impressed (I donât have windows).
Sounds like you have an ubuntu user environment. Great. Make sure you are using a bash shell (type âecho $SHELLâ)
If youâve downloaded your file and named it convert_daily_notes.sh, thatâs okay. Try typing this at your command prompt from inside the folder where you have the script:
chmod 755 convert_daily_notes.sh
that will make the script executable
then try running just the ls command from your vault and see what you get
ls *,\ 202[01].md
if everything is working, it should list all your daily notes from 2020 and 2021, assuming they are also all in the vault root as they would be after making a roam markdown export.
Finally try running the full command
ls *,\ 202[01].md | ./convert_daily_notes.sh
(assuming your convert script is also in the vault root)
remember to close obsidian before running that; it could take awhile
Returns âchmod: changing permission of âconvert_daily_notes.shâ: Operation not permittedâ
ls *,\ 202[01].md
Works as expected and lists everything
ls *,\ 202[01].md | ./convert_daily_notes.sh
Then returns â./convert_daily_notes.shL line 15: 2020-04-12.md: Permission deniedâ
Iâm not sure whether this is related to the lack of permission earlier or whether there is something specific to this file (there is no file called â2020-04-12.mdâ, but there is âApril 12th, 2020.mdâ)?
The folder is in OneDrive, so Iâve turned off sync
Iâve checked all instances of Obsidian are closed (and exited)
Iâve moved the âApril 12th, 2020â out of the vault and now have the following:
sed: preserving permissions for â./sedLc9028â: Operation not permitted
sed: cannot rename ./sedLc9028â: Permission denied
touch: setting times of â2020-04-13.mdâ: Operation not permitted
This was completely right!!! The problem was OneDrive (as it always is!) - I needed to make sure that the folder was âAlways available on this deviceâ!
100% converted - thank you SO much pmbauer - Iâll write more complete notes on how I did this for future Windows users later in the week
Hi @pmbauer â this is exactly what I was hoping to find. alas iâm on Mac OS X and donât speak bashâ so I understand that you wonât be able to replicate exactlyâ but maybe thereâs a small chance:
I replaced sed with gsed and saved the script on the roam markdown export folder âwhich Iâve renamed as roam
ran chmod 755 convert_daily_notes.sh and the test ls command â which worked
however, when I ran ls *,\ 202[01].md | ./convert_daily_notes.shâ the response I got was
date: illegal option â -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] âŚ
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]indent preformatted text by 4 spaces
Any chance you might know what happened here/ how I might be able to fix it?
from your prompt, what does which date say? it probably needs to point to a symlink to someplace in the brew packages (needs to be gnu date). if itâs /usr/bin/date, probably still using the bsd date utility.
Hey, any update on that step-by-step Windows conversion guide? Would love to be able to convert these daily note pages with links intact. (And daily more annoyed that Roam devs thought this naming convention would be a good idea in the first place)
I believe @jimw 's issues were due to onedrive not having all the files downloaded.
The script should just work if you
Iâve installed Ubuntu from the Windows store and have created the âconvert_daily_notes.shâ file within the relevant vault using the nano editor.
So if you install the Windows Subsystem for Linux the script should just work in that environment. You can ignore the MacOS X instructions. (I donât have a windows install handy to confirm this).
Lets say Iâm a year in to using Obsidian and have already used this script successfully to convert everything during my initial migration from Roam, but continued using the âMMMM Do, Yâ format for my Daily Notes (and their file names). Realizing now that I shouldâve stuck with the YYYY-MM-DD format due to the majority of plugins I use referencing the YYYY-MM-DD format.
Could I technically run this convert all of my dates, file names, (and any date shown on any note using âMMMM Do, Yâ to âYYYY-MM-DDâ format?
I use MacOS 13.1 and followed the instructions to brew install bash gnu-sed gnutls. I kept running into issues when setting the environment, but managed to get it up and running by specifying gdate, gsed and gtouch in the code.
#/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
roam_date_to_obsidian() {
gdate --date="$(echo "${*}" | gsed 's/th//;s/nd//;s/rd//;s/1st/1/')" \
'+%Y-%m-%d'
}
while IFS= read -r line; do
roam_daily_note=${line/%.md/}
obsidian_daily_note=$(roam_date_to_obsidian ${roam_daily_note})
# add front matter
echo "---" >> ${obsidian_daily_note}.md
echo "tags: [daily]" >> ${obsidian_daily_note}.md
echo "---" >> ${obsidian_daily_note}.md
cat "${roam_daily_note}.md" >> ${obsidian_daily_note}.md
# update links
gsed -i "s/\[\[${roam_daily_note}]]/[[${obsidian_daily_note}]]/g" *.md */*.md || true
# give it a relevant timestamp
gtouch -d ${obsidian_daily_note} ${obsidian_daily_note}.md
rm "${roam_daily_note}.md"
done```
Just in case it helps someone else.