this sounds like a python kind of problem. i'm all for abusing bash features but there comes a point when there's just too many brackets.
Linux
Welcome to c/linux!
Welcome to our thriving Linux community! Whether you're a seasoned Linux enthusiast or just starting your journey, we're excited to have you here. Explore, learn, and collaborate with like-minded individuals who share a passion for open-source software and the endless possibilities it offers. Together, let's dive into the world of Linux and embrace the power of freedom, customization, and innovation. Enjoy your stay and feel free to join the vibrant discussions that await you!
Rules:
-
Stay on topic: Posts and discussions should be related to Linux, open source software, and related technologies.
-
Be respectful: Treat fellow community members with respect and courtesy.
-
Quality over quantity: Share informative and thought-provoking content.
-
No spam or self-promotion: Avoid excessive self-promotion or spamming.
-
No NSFW adult content
-
Follow general lemmy guidelines.
Yeah, I probably should use Python, it just takes me longer and I am much less likely to keep hacking around with it later. It feels like a foreign language relative to bash. The problem came from greping using for loops, so I'm in that mindset. Point taken though.
readable script that I will understand at a glance a year later
Well that rules out bash
I think this post could use some small example with what you have vs what you want to get
Depending on how I read your description it's either doable with bash and grep or probably doable but a lot of hassle compared to using something else than bash
jake
Jake
j4ke
Jak3
j@k3
JAK€
jπ⸦kE
𝚥ᎪᏦ⋲
ꓙᏎ🅺Ꮛ
𞋕ꮜ𝈲𝈁
᜴ᚣᜩᗕ
It is not this, but same problem scope. Resolve all to "jake" for further processing. Also specifically looking for that ck.
tr could definitely do some work here. maybe something like, echo each word and its translated counterpart, sort on first column, and then echo $col1 >> $col0 for each line? it's a start at least
If you want ᜴ᚣᜩᗕ to get resolved to jake then bash will be a pain to use. I would use python
For each ASCII letter create a list of non-ASCII characters that look similar. Then, for each word you want to match construct a regex
dictionary = { ...'j': ['j', 'J', '𝚥', '𞋕', ...
regex=''
for letter in 'jake':
regex += f'[{"".join(dictionary[letter])}]'
- so after whole loop the regex would look a bit like (I'm cutting out a lot of characters to save on copy-pasting)
[jJ𝚥𞋕][aA4@][kKᏦ🅺][eE3€]
>>> import re
>>> r='[jJ𝚥𞋕][aA4@][kKᏦ🅺][eE3€]'
>>> re.fullmatch(r, 'jake')
<re.Match object; span=(0, 4), match='jake'>
>>> re.fullmatch(r, 'joke')
>>>
In general the group of problems that you are touching here is https://en.wikipedia.org/wiki/String_metric but I'm not sure if there is an algorithm that would be so "visual" matching
Thanks. This was helpful.
Similar to the other comment, not sure if you've ruled out writing a Python script? For what you're describing Python would be able to easily tackle your requirements and still be readable since it's just a script you can launch whenever you need. Python is also pretty easy to pick up so if you're familiar with scripting then it could be a fun learning experience (if you don't already know it).
Other scripting languages could work too, just feel like Bash will be less readable if you're writing a massive script like that.
If you have raw jdon, then take a look at jq. It's amazing for read json text in bash
If it's a regular enough format, you could just use DuckDB. Are you using it as a challenge?