2 ms·
In my mind, the greatest strength of awk as a scripting language is its widespread availability. Whether you're using a modern Mac fresh out of the box, GitBash
by RodgerTheGreat 3y ago
In my mind, the greatest strength of awk as a scripting language is its widespread availability. Whether you're using a modern Mac fresh out of the box, GitBash on a windows machine, or talking to a router over SSH, you can be confident that some version of awk is close at hand. The cost of this ubiquity, however, is extreme fragmentation. As is usually the case with GNU extensions, gawk provides a variety of shiny baubles which absolutely cannot be counted upon if you want to write a portable script. As a result, they're traps for the unwary to at least the same extent as they are handy tools.
There are a variety of small features which could greatly enhance the flexibility of awk, including things described in this article and more ambitious ideas like making associative arrays first-class values, but if they aren't broadly supported, I don't imagine they'd have much impact. If I need to install a specific version of awk to run a script (and I have the ability to do so), I could just as easily install one of dozens of other capable scripting languages instead.
- statquontrarian 3y agoMy first question to any programming question is, "can I reasonably solve this with awk?" exactly for its ubiquity. I stick to the POSIX standard for the reasons you note: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/a... If POSIX awk is insufficient, then I probably should be using something other than awk, so its limits are actually a good guardrail; however, it's shocking how powerful POSIX awk is with built-in arrays, hashmaps, regular expressions, etc., although no doubt there are quirks.
- classichasclass 3y agoAnd this is where Perl 5 says hi. It's also widespread and easily available, can do anything awk can, and isn't similarly fractured (Raku now being its own spinoff world). The article's complaints about its syntax are a matter of taste, of course.
- mst 3y agoAnd the article's complaint about its stat() interface, while accurate in theory, misses the existence of https://p3rl.org/File::stat https://p3rl.org/File::stat (and there's some similar other modules for things like localtime()) which gives you named access. Also being able to use https://p3rl.org/App::FatPack https://p3rl.org/App::FatPack to bundle (pure perl) dependencies along with your code into a single script file to ship around makes life significantly easier deployment-wise (and https://p3rl.org/Object::Remote https://p3rl.org/Object::Remote allows for 'no deployment at all', it runs 'ssh <target> perl -' and ships the code it needs across the wire on connect).