Awk is the coolest tool you don't know
portal.drewdevault.com
portal.drewdevault.com
Its limitations force you to solve problems in a creative way, and it can be a good programming exercise.
On the other hand, it can't handle UTF-8, which is annoying. (Yes, I know about Gawk).
The world took a wrong path when *nix tools were no longer seen as appropriate things for ordinary people to learn. (Yes, in the 1980s clerical staff in some companies were taught awk or even Emacs.) Productivity of the labour force would only rise. When my spouse moved to my country and didn’t yet know the local language, she worked for a multinational outsourcing firm. The job turned out to be little more than glorified data entry and it could have been easily automated with *nix tools piped. Hiring educated people to sit 8 hours a day and do everything manually was a waste of money and human potential.
Traditional nix tools come with a lot of UX baggage. A full programming language is likely better for some tasks, though *nix tools still have their place.
Your experience sounds similar to mine. Generally, my scripts are ad hoc and use only a handful of features at a time. They only need to be complex enough to get my data to the next stage in the pipeline, where another tool would probably work better.
Edit: fixed link
https://ia902309.us.archive.org/25/items/pdfy-MgN0H1joIoDVoI...
Minor simplification on the line numbering example, there's a builtin variable for counting records (NR or FNR) so no need to introduce your own counter:
awk '{print NR "\t" $0}' < somefile
There are other builtins that are quite handy as well. The only thing that bugs me at times is when I want to print a range of records like column 5 to end, where the total number of columns varies. I wish there was a simpler way to do that like a column range selector. This is where I sometimes use 'cut' since its so simple to do column ranges (unless the column separators have consistent whitespace; then cut doesn't work).As someone who speaks sed I thereby found this part super confusing:
> In this manner I used it as a kind of modified sed which only operates on certain lines.
But... sed already does that, with the same syntax even? (Note that I don't have BSD sed handy... I would normally use \0, but that & works fine in gsed.)
> awk '/^\/\// { gsub(/\[[a-zA-Z:]+\]/, "[&]") } { print $0 }'
> sed -e '/^\/\// { s/\[[a-zA-Z:]\+\]/[&]/g; }'
*https://drewdevault.com/2020/11/01/What-is-Gemini-anyway.htm...
For example I recently needed to check for log output where two columns differed. For a simple case like this awk would have probably done the job too but Ruby and Perl just have so many functions built in.
... | ruby -ne '$_.chomp =~ /^added (.*) ipfs\/([^\/]*)$/ and $1 != $2 and print'
Perl supports similar `-n` and `-e` flags. It even makes it a bit easy to do the regex filter and match (The argument is implicit IIUC) but I tend to prefer Ruby because Perl has too many sigils for a casual user to remember.For cases where it needs to be automated, Awk is probably the best tool. I don't know it though, and cases are few enough and far between so I've always just used Python.
git ls-tree -r HEAD | cut -f2 | xargs -n1 sed -n "/^\/\//p;1q" | less* Append line number: `cat -n FILE`