
Bash script for transforming markdown table to the Anki card format in Obsidian.
https://github.com/HHChuang/Tools-in-Obsidian/blob/main/src/toAnkiCard.sh
Language learning requires extensive practice, which can be broadly categorized into two methods: passive and active learning. Passive learning involves acquiring a language through repeated exposure without intense focus. For example, listening to a podcast in the target language while doing housework is a form of passive learning. In contrast, active learning[^1] requires dedicating focused time to engage with the language in specific contexts. As language learners, we need both methods and a balance between them[^2].
In my active learning workflow[^6], I need to transform a markdown table into Anki card format in Obsidian. This table contains all the vocabulary I don’t know or am unsure about. To utilize the powerful spaced repetition system[^3] from Anki, I need to write all the vocabulary in a specific format such that the Obsidian plug-in, Obsidian_to_Anki, export them from Obsidian to Anki database. Initially, I tried creating the Anki card format manually, but it was too time-consuming and did not fit well into my workflow. After some trial and error, I decided to write a bash script[^4] to automate the process.
- Pre-requested plug-in:
- Obsidian
- Anki
- Obsidian plug-in: Obsidian-to-Anki[^5]
Demonstrate process with an example
Prepare a Markdown table
I am using an English book[^7] that I started reading recently as an example. First, I use the Kindle app to read and highlight new vocabulary without interrupting my reading flow. Then, I import these highlighted words into my Obsidian notes using Readwise.
I organize the highlighted vocabulary into a table like this:
| Front | Back | Example |
|---|---|---|
| ostrich | <li>os-trich</li><li>a very large African bird with a long neck and long legs, that cannot fly but can run very fast </li><li>(informal) a person who prefers to ignore problems rather than try and deal with them</li> |
We want to bury our heads in the sand like ostriches to avoid the storm. Location 687 |
| custody | <li>cus-tody</li><li>the legal right or duty to take care of or keep somebody/something; the act of taking care of something/somebody</li><li>the state of being in prison, especially while waiting for trial</li> | If we have a custody hearing, what will my kids say? Will they talk about how distraught Mom is and that she’s too busy and upset to spend any time with them? Location 951 |
| rebel | rebel (against somebody/something) to fight against or refuse to obey an authority, for example a government, a system, your parents, etc. | To rebel against the spouse may be, in reality, to rebel against the parents. |
This table is part of my reading notes, particularly for language learning. The advantage is that when I have time to read again, I can use this table as a cheat sheet to help me easily overcome language barriers. Additionally, spaced repetition is essential for transforming these short-term memories into long-term memories, and I utilize Anki for this purpose. As I mentioned before, this table cannot be used with the Obsidian plug-in, Obsidian_to_Anki, and needs to be transformed into a specific format, like

toAnkiCard.sh: Transform Markdown table into Anki-card format
To convert the table into the desired format, I use a bash script called toAnkiCard.sh[^4] in VSCode or any command-line terminal. Both this bash script and example markdown files are available on my GitHub[^9]. The script first checks if there is an existing Anki card, and then it transforms the markdown table into the Anki card format. We will start with a clean file as an example. The input markdown file is Rebuilding_before.md[^8]. To execute this script, follow the instructions provided.
$ toAnkiCard.sh Rebuilding_brfore.md
with the screenshot

The resulting file is Rebuilding_after.md[^10], where you can see explicit how this script work and the changing of markdown files.
If there is an existing Anki card in the markdown file, it updates the new vocabularies. The input markdown file is Rebuilding_update.md[^11]
$ toAnkiCard.sh Rebuilding_update.md
with the screenshot

The resulting file is detailed in Rebuilding_after.md[^10]. This time, the script counts a total of 15 vocabularies, of which 13 are existing words. It updates only 2 new vocabularies in this process.
To complete the workflow, I also demonstrate in the next section how to update these Anki cards in the Anki database.
Use Obsidian_to_Anki to update Anki-Card to Anki database
Start from this Anki card format in Obsidian,

We execute the Obsidian_to_Anki plugin by scanning the vault, assigning each card an ID, and updating them in the Anki app.

The new ID, found in line 242, is only visible in edit mode, not in preview mode in Obsidian.

Next, we will open the Anki app to check if the card has been updated. Here, you can see how the card appears in the app by browsing the database.

In the practice mode, the card is present in its front and back form.

This concludes this part of my language learning workflow. Thank you for reading!
[^1]: Active Learning in Language Development
[^2]: From this youtube video, it explains the balance between active and passive learning.
[^3]: Wiki
[^4]: toAnkiCard.sh code in my GitHub
[^5]: GitHub repo.: Obsidian-to-Anki
[^6]: The whole language learning workflow will be update someday.
[^7]: Rebuilding: when your relationship ends
[^8]: Rebuilding_before.md
[^9]: My GitiHub repo. Toos-in-Obsidian
[^10]: Rebuilding_after.md
[^11]: Rebuilding_update.md

</li><li>(informal) a person who prefers to ignore problems rather than try and deal with them</li>
Leave a comment