Undesired and Duplicate Tags

I recently began using Obsidian. I have imported a couple of decades of notes from other less capable note suppositories. Upon doing so, I found many tags that were either unnecessary or had very few hits. Although there were many I found it easy, using Tag Wrangler, to rid my documents of these tags by simply renaming them to an existing meaningful tag.

Unfortunately, in so doing I created another situation. I now have many documents with duplicate tags. That is the same tag written twice. I have searched for a solution (preferably a global solution) and found nothing.

Does anyone know how I can easily resolve this issue?

Are these duplicated tags on the same line, or multiple lines?

If they’re on the same lines, you could do a search for something like /#tagA.*#tagA/ and it would return those matching. If they are on multiple lines, you should theoretically be able to do /#tagA*#tagA/s and get similar matches, but alas that doesn’t work in Obsidian (Not sure if Obsidian supports any flags for the regex’s… )

If they’re defined the tags property one could query them using dataview, but one needs to differentiate between the tags: a, b, c and the list variants. So using these two queries I could detect duplicates within the tags property:

## Comma separated tags property
```dataview
TABLE WITHOUT ID key[0] as File, key[1] as tag, length(rows) as Count
WHERE typeof(tags) = "string"
FLATTEN split(tags, "\s*,#?\s*") as tag
WHERE tag
GROUP BY [file.link, tag]
WHERE length(rows) > 1
```

## Tags property as a list
```dataview
TABLE WITHOUT ID key[0] as File, key[1] as tag, length(rows) as Count
WHERE typeof(tags) = "array"
FLATTEN tags as tag
WHERE tag
GROUP BY [file.link, tag]
WHERE length(rows) > 1
```

These query will list which file it found the duplicates in, and which tag was duplicated, and the last column is how many times it was duplicated.

Lastly, if your tags are duplicated as inline tags on different lines, I’m not sure how to detect them. I reckon, but haven’t tested, that Visual Code could use the /.../s regex from above to properly search for them.

Thanx for this. I’m going to use it.

Try duplicate Files Deleter program