Count number of times a tag has appeared in my vault

Is there a way to count the number of times a particular tag #win has appeared in my entire vault?

If in a note, this tag was used 7 times, it should be counted 7 times.

I am trying to use the dataview plugin but since I just discovered it 30 minutes ago, I didn’t have any luck so far.

1 Like

This is not going to be something dataview is good at, I think. If you had a field in your note that said Wins:: 7, then it’d be great for dataview. Does Obsidian’s built-in search give you a results count? If you did an embedded search query for your tag can you get it to show all 7 reaults for a note?

Try this Dataview snippet.

TABLE length( as numfiles  FROM "/" 
flatten file.tags as tag group by tag 
sort length( desc limit 10

I thought the tags field only could detect a tag’s presence or absence in a file. OP wanted the tag counted multiple times if it was present multiple times in the aame file. Is there a count somewhere in the tags field that I’m not aware of?

@jwl Thanks, but it only shows in how many files, a tag has appeared. Not how many times a tag has appeared.

No and No.

I don’t think dataview indexes that data.

One idea I had was to use dataviewjs, get each file with tag #win, then read the file in JS and use regex to count how many times #win appears in the file. But I didn’t want to spend more time tweaking dataview.

In the end, I just wrote this one-line bash script that I would run when I want to count the tags. :slight_smile:

grep -r "#win" ~/full/path/to/vault | wc -l
1 Like

Sounds like a perfectly reasonable way to go!
Hopefully you can mark your script as the solution to this thread.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.