4 ms·
AWK is truly a gem. While it has some warts and quirks, it is nevertheless an extremely flexible, performant, and simple scripting language whose omnipresence i
by RodgerTheGreat 2y ago
AWK is truly a gem. While it has some warts and quirks, it is nevertheless an extremely flexible, performant, and simple scripting language whose omnipresence is a remarkable asset.
It's rather far afield from AWK's normal range of applications, but I recently wrote a portable AWK-hosted interpreter[0] for my own general-purpose scripting language, which provides some handy options for bootstrapping. It would be very interesting to explore building tools like assemblers or even a simple C compiler in AWK.
[0] https://github.com/JohnEarnest/Decker/tree/main/tools/awk/ https://github.com/JohnEarnest/Decker/tree/main/tools/awk/
- Brian_K_White 2y agoA couple of times I wrote the same thing in both bash (pure, no externals) and awk just for the heck of it, and the end result was the 2 programs were practically the same. I didn't expect that! Maybe I'll dust that off and make it intentional just to see how small I can get the diff. Maybe even manage to make a polyglot.
- RodgerTheGreat 2y agoThe biggest difference for general-purpose programming is that AWK supports floating-point arithmetic (and in some implementations arbitrary-precision arithmetic), while bash does not. Shelling out to AWK is a much more portable approach to performing floating-point calculations in bash than "bc" or "dc", since it's available in more environments. Older versions of bash also have extremely limited or nonexistent support for associative arrays, which can pose challenges compared to AWK. I think AWK has much nicer, less surprising syntax than bash, but that's just a subjective opinion.
- Brian_K_White 2y agoDefinitely to get power out of bash, you end up with write-only code with half the logic in all the exansions and word splitting hacks.