Zettelkasten Forum


Script to print all tags from .txt files (run from archive directory)

2»

Comments

  • Counting occurrences instead of notes?

  • @toddgrotenhuis said:
    I've been trying this:

    find . -type f -print0 -not -name '.*' | xargs -0 grep -EIoh '(?:^|\s)#[A-Za-z0-9_ÄÖÜäöüß-]+' |sort | uniq -c | sort -rn > "Tag List.txt"

    Remove the 0-9. This will eliminate all instances where you have a # symbol followed by a number as in the numbered lists you have created. Be sure and not start a tag you care about with a number.

    If you had a space between the # and the number in your numbered lists, you wouldn't have this problem.

    try
    find . -type f -print0 -not -name '.*' | xargs -0 grep -EIoh '(?:^|\s)#[A-Za-z_ÄÖÜäöüß\-]+' |sort | uniq -c | sort -rn > "Tag List.txt"

    Will Simpson
    I must keep doing my best even though I'm a failure. My peak cognition is behind me. One day soon I will read my last book, write my last note, eat my last meal, and kiss my sweetie for the last time.
    kestrelcreek.com

  • Ok, one more piece of advice, please? I'm getting some with a preceding space and some without, and not sure why?

    41 #inbox
    3 #inbox

  • I'm not sure what you mean by "a preceding space and some without," in your specific example.
    I get better formating of the tag list if I use the following. I'm excluding file with a ★ which includes "★ Tag Cloud.md" else the macro counting all the tags in the tag cloud and adding it to the total.

    cd /Users/will/Dropbox/zettelkasten/ egrep --exclude="★*.*" -ohsr "(?:^|\s)#[A-Za-z0-9_ÄÖÜäöüß\-]+" -- * | sed -e 's/[[:space:]]#/#/' | sed /^[^#]/d | sort | uniq -c | sort -t# -k2 > "★ Tag Cloud.md"

    Will Simpson
    I must keep doing my best even though I'm a failure. My peak cognition is behind me. One day soon I will read my last book, write my last note, eat my last meal, and kiss my sweetie for the last time.
    kestrelcreek.com

  • Hi, I was poking around to see if tag index functionality ever made it into this program and came across this post. If anyone could please explain how to run it in simpler terms for a non-programmer with extremely basic coding skills, I'd greatly appreciate it.

  • @rdp123, I'll give it a try.

    Open the Terminal app.
    Type the following command to switch to your ZK directory; You'll have to change the destination directory to the folder where your ZK is.

    cd /Users/will/Dropbox/zettelkasten/

    Once you are in your ZK directory, copy and paste this command into Terminal, and on pressing return, nothing will happen. This command only searches the notes and does not modify them. It can be run as many times as needed. So you know, I've changed the command to be faster and only look at .md files. If your note files use a different extension, you'll want to alter the ".md."

    egrep --exclude="★*.*" -ohs "(?:^|\s)#[A-Za-z0-9_ÄÖÜäöüß\-]+" -- *.md | sed -e 's/[[:space:]]#/#/' | sort -t# -k2 | uniq -c > "Tag Cloud.md"

    Now you can switch to The Archive, and you should have a new note titled 'Tag Cloud.'

    Let me know if this works for you.

    Will Simpson
    I must keep doing my best even though I'm a failure. My peak cognition is behind me. One day soon I will read my last book, write my last note, eat my last meal, and kiss my sweetie for the last time.
    kestrelcreek.com

  • That worked! Thank you!!

  • Another way is to use the fine Obsidian app:
    Point to your archive folder (by making a vault).
    Install the file pane in settings.
    CMD-P and choose chow tags.

    Will make a nice list of all tags, and how many times they are used.

  • Pardon my total ignorance of all this, but is it possible to modify this so that it's case-insensitive. Thank you for your help!!

    @Will said:
    @rdp123, I'll give it a try.

    Open the Terminal app.
    Type the following command to switch to your ZK directory; You'll have to change the destination directory to the folder where your ZK is.

    cd /Users/will/Dropbox/zettelkasten/

    Once you are in your ZK directory, copy and paste this command into Terminal, and on pressing return, nothing will happen. This command only searches the notes and does not modify them. It can be run as many times as needed. So you know, I've changed the command to be faster and only look at .md files. If your note files use a different extension, you'll want to alter the ".md."

    egrep --exclude="★*.*" -ohs "(?:^|\s)#[A-Za-z0-9_ÄÖÜäöüß\-]+" -- *.md | sed -e 's/[[:space:]]#/#/' | sort -t# -k2 | uniq -c > "Tag Cloud.md"

    Now you can switch to The Archive, and you should have a new note titled 'Tag Cloud.'

    Let me know if this works for you.

  • Replace uniq -c in the command pipe with uniq -c -i to ignore case

    Author at Zettelkasten.de • https://christiantietze.de/

Sign In or Register to comment.