Find txt file containing string via Shortcuts?

I’m building a shortcut to update / annotate clipped web content. When updating I need to find a file in a folder On iPhone (Obsidian) that contains a string in the file e.g. url: https://talk.automators.fm. How can I do that efficiently inside Shortcuts / background without having to switch to an app?

There are about ~2500 txt files in a single folder. As a reference: a grep command on macOS can find a file in < 1s

What I’ve tried:

  • Using the Files actions is too in efficient; it takes huge amounts (minutes) of time to open all files (~2500) and loop through them]
  • Obsidian Actions can find the file, but needs to switch to the app also (although they try to hide the switch by blacking it out; understandable, but a hack
  • a-Shell can use grep and even has shortcuts support, but no access to On iPhone > Obsidian in the Shortcuts runner (it does work in the a-Shell app). There’s a relevant issue here: Extension no longer has access to folders from `pickFolder` · Issue #729 · holzschu/a-shell · GitHub

Are there any other ideas how to identify a file based on a string in the content via Shortcuts?

You could build a separate index like you would for a database. Read in say a dictionary from an index file that you periodically regenerate. That dictionary holds the file name against the URL (you may just find you have to escape or encode some characters in the key). Then you can forego the scanning of all files live and update the corresponding file directly.

Thanks @sylumer - that is indeed a good workaround. It does mean duplication of content (e.g. the URL of a piece of content would be defined in two places…) If I can’t make a-Shell or another efficient solution work, that would be something I will try out.