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
bash sed 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 sed date and bash are on your path.
export PATH=/usr/local/opt/coreutils/libexec/gnubin:$PATH
export PATH=/usr/local/opt/gnu-sed/libexec/gnubin:$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
Related