Skip to content

Instantly share code, notes, and snippets.

@chrisgrieser
Last active December 31, 2023 02:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisgrieser/248579475461750771dd44d96bc3f81f to your computer and use it in GitHub Desktop.
Save chrisgrieser/248579475461750771dd44d96bc3f81f to your computer and use it in GitHub Desktop.
Change Wikilinks in YAML Frontmatter from the Breadcrumbs style to the new Obsidian Metadata Style
# macOS
cd "path/to/your/vault"
awk 'FNR <= 1 && /^---$/{print FILENAME}' **/*.md |
xargs -I {} sed -i '' -E '1,/^---$/ s/(\[\[.*]])/"\1"/g' "{}"
# Linux (or macOS users with GNU sed)
cd "path/to/your/vault"
awk 'FNR <= 1 && /^---$/{print FILENAME}' **/*.md |
xargs -I {} sed -i -E '1,/^---$/ s/(\[\[.*]])/"\1"/g' "{}"

ℹ️ This operation is mostly relevant for Breadcrumbs users, who have wikilinks in their yaml frontmatter that needs to be converted to quoted wikilinks for Obsidian 1.4

  • The awk command ensures that only files that have frontmatter are affected.
  • The sed command is restricted to apply the change only to wikilinks in the frontmatter, not elsewhere.
  • The command works fine in my vault, but I haven't tested it elsewhere, so please make backups before. (If you use git, use git diff afterwards to check all changes.)
---
parent: [[My Note]]
children:
- [[Other Note]]
---

[[My Note]]

Only the wikilinks in the frontmatter are affected:

---
parent: "[[My Note]]"
children:
- "[[Other Note]]"
---

[[My Note]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment