On 2024-05-22 17:04, Lawrence Velázquez wrote:
Yes, it's quite common -- borderline universal -- to start with sed
and pick up awk later.
Good to know.  Sometimes I think I get everything wrong.
You take this way too far, in my opinion.  Compared to appropriate
external tools, zsh-heavy solutions often perform poorly and are
more difficult to understand and maintain.  (Compare your original
code to the awk solutions Mark and Roman offered.)  Most of your
code would improve if you (judiciously) used more external utilities
and less zsh.
It seems 'obvious' that internal code would be faster, but I know from Roman's various tests over the years that it ain't necessarily so.    Besides, at the concept level, shells are intended as glue between system commands and all their internal abilities are addons.  I suppose when,  as you say, one replaces a multi line internal construction with a single line construction that calls an external prog. the mere fact of many lines to interpret has a penalty right there that you'd not notice in a compiled program.