|
|
Subscribe / Log in / New account

The state of the AWK

The state of the AWK

Posted May 20, 2020 10:55 UTC (Wed) by NAR (subscriber, #1313)
Parent article: The state of the AWK

AWK reads the input a line at a time. A line is scanned for each pattern in the program, and for each pattern that matches, the associated action is executed.

I think awk started to lose its relevance when data started to be structured differently (XML, JSON, etc.) than by sequence of lines. I don't remember the last time I wrote an awk script, for one-liners perl suffices (with the -e and -n options) - and perl can be used to build bigger programs, so what's the point in keeping up with AWK? Similarly I just realized how odd is writing HTML tags into this form when all other forms I use requires Markdown and I automatically almost started to type it when I realized where I am :-)


to post comments

The state of the AWK

Posted May 20, 2020 18:28 UTC (Wed) by jthill (subscriber, #56558) [Link]

If communicating with the less dedicated is in the mix, perl loses its luster. Awk is much, much more approachable. If I'm trying to explain to someone who won't be doing a lot of scripting how to munge text, flat files, awk's by far the best option if sed isn't easier. They'll likely be able to extend what they've learned because the marginal costs are low, and if awk's out of steam they're likely to need some guidance for other reasons.

json and xml are big hammers, far too often people swing them for little jobs.

The state of the AWK

Posted May 20, 2020 23:57 UTC (Wed) by wahern (subscriber, #37304) [Link]

Alas, Red Hat/CentOS/Fedora no longer install Perl by default. There was a glorious period where Perl was more common than Bash, after the BSDs and commercial Unices adopted Perl, but before the dark years of "shell scripting" becoming synonymous with "Bash scripting". If you had reason to venture away from POSIX utilities for system management tasks, Perl was the obvious and perfectly reasonable choice--it was and remains the better AWK.

I think AWK is seeing a resurgence precisely because Perl isn't as ubiquitous as it once was. You can't depend on Python being installed, either, and even if you could it still sucks for short, shell-style programming. Which is why as Python has displaced Perl, there's more demand for AWK to fill the remaining gap.

I agree that XML and JSON have altered the landscape, but XML and JSON don't fit streaming paradigms very well. Even when something like jq is available, I usually find the regular shell utilities to be far more convenient, and AFAICT so do most others. It's always been the case that for highly structured data you ended up using more sophisticated programming languages, anyhow. The reason why the Unix shell and shell programming have persisted for so long is precisely because the "one language to rule them all" and "one record format to rule them all" approaches never sufficed nearly enough to displace ad hoc text munging tools. The very nature of the problem domain--gluing together disparate, uncooperative tools and data--contradicts the idea that there could ever be a simple, unified solution.

The state of the AWK

Posted May 21, 2020 15:57 UTC (Thu) by smitty_one_each (subscriber, #28989) [Link]

let awk and jq be the Batman and Robin of the command line.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds