I’ve often written incantations many lines long and even broken out to actually writing awk scripts from time to time.
Once the penny drops with it it’s great fun but it’s absolutely useless once your problems get to any degree of sophistication.
I typically move into Python at this stage. Perl and Ruby are probably a more elegant fit here but those aren’t rows I want to have.
In this day and age, awk really needs CSV (RFC-4180) support and better semantic scoping and library support.
I’d also think it would be neat as an embedded language for various data processing platforms but if we haven’t seen it yet I doubt we will ever see it.
EDIT support for file formats beyond plain text would also be a winner.
https://arstechnica.com/gadgets/2022/08/unix-legend-who-owes...
(Note I still use Python/C++ for real programs; perl is only for one-liners to replace the AWK)
Can you say some more about this, what kind of file format do you want? JSON? XML?
Of course no awk will run an empty program, so the article's '1' or '"a"' or other truthy value is required.
I believe Awk's semantic behaviour is a kindred spirit of Perl's autovivication[0].
It is often handy and sometimes can bite one in the proverbial backside.
For an opposite example, consider: a 1000 statement JS program is perfectly fine. A 1000 statement AWK script is very evil, most people would be saying it should be replaced with real language ASAP.
awk '!a[$0]++'
awk '/search/{n=2} n && n--'
> The syntax of JavaScript 1.0 was directly modeled after the statement syntax of the C programming language with some AWK inspired embellishments.
(the rest of the section is also interesting in that respect).
[1] https://dl.acm.org/doi/10.1145/3386327 (CC-BY open access)
I'm not sure what has happened then.
<link rel="canonical" href="index.html">
I had to stop submitting ISC SANS posts because they similarly have a canonical link in their head which HN, for reasons I'm not sure about, use to 'correct' the URL, errantly.I can turn that off for specific domains - if you email the relevant info to hn@ycombinator.com I'll take a look.
awk -v FS=';' -v OFS=',' 1
I expect this to change the change the separator in the output. Period. The “efficiency” argument for why it doesn’t work just doesn’t cut it for me. First, it’s very simple to do a one time comparison of FS and OFS, if they are different then you know you know you _have_ to perform the change, because the user is asking you! If I do this in reality and it doesn’t work I just switch over to sed or perl and call it a day.All in all, perl -eP is a better awk. And for data processing I switched to miller. It has it’s idiosyncrasies as well but it’s much better for working with structured records.
{ gsub(/\;/, ","); print }
Damn those far-too-common-word names! Betcha if I googled that, I'd get page after page of results pointing to actor Johnny Miller... Any link?
[EDIT:] Naah, sorry, just had to search for "miller language" (and remove the superfluous "academy" from "miller language academy" that Google "helpfully" added), and found: https://miller.readthedocs.io/en/latest/miller-programming-l... . Thanks, interesting!