7 ms·
Awk is awesome! Glad that they are looking to modernize the book. It wasn't really necessary, all the code examples in the original edition of the book still ru
by siraben 3y ago
Awk is awesome! Glad that they are looking to modernize the book. It wasn't really necessary, all the code examples in the original edition of the book still run just fine, although some are somewhat dated, like printing ASCII bar graphs. They also had examples of writing VMs, parsers and interpreters in the book, which run on modern implementations.[0]
The language has some quirks. To declare temporary variables, it's common practice to add extra arguments to functions that won't be used. And traversal of associative arrays is implementation-dependent. I'm not sure what the situation is regarding locale and UTF-8 support.
EDIT: Looks like Brian Kernighan added Unicode support last year.[1]
[0] https://github.com/siraben/awk-vm/blob/master/vm.awk https://github.com/siraben/awk-vm/blob/master/vm.awk
[1] https://github.com/onetrueawk/awk/commit/9ebe940cf3c652b0e373634d2aa4a00b8395b636 https://github.com/onetrueawk/awk/commit/9ebe940cf3c652b0e37...
- bluetomcat 3y agoIs there a particular benefit in writing a VM in AWK, placed in a big BEGIN block? Very similar code can be written in Perl or Python. Isn't the strength of AWK in its line-matching capability, being able to pattern-match a line against a block of code?
- siraben 3y ago> Is there a particular benefit in writing a VM in AWK Not really. Later on the book just ran out of line-matching examples to go through and started doing regular programming instead :P. When I actually write AWK code I rely on line-matching and using a variable to handle state.
- pdw 3y agoAt the time, awk was the only scripting language (other than shell) generally available on Unix systems. Perl, Tcl, Python didn't exist yet. So awk was often used for general-purpose programming.
- ufo 3y agoI love telling about that example to my programming language friends. > Hey you should read the AWK book, it even says how to write a VM! > Why would I ever want to use AWK for that? > Well, the input is a text file with one space-delimited instruction per line. > Hmm... You have a point.
- chasil 3y agoAWK runs everywhere. Perl and Python do not. Busybox has their own independent AWK implementation. https://busybox.net/ https://busybox.net/ https://frippery.org/busybox/ https://frippery.org/busybox/ Also see the first edition of the AWK manual online here: https://archive.org/details/pdfy-MgN0H1joIoDVoIC7 https://archive.org/details/pdfy-MgN0H1joIoDVoIC7
- unmole 3y agoI'm sorry, where does Awk run but Perl and Python don't? If we're counting minimalist implementations, there's micropython that even runs on microcontrollers that cost a less than 2 dollars.
- dredmorbius 3y agoThe POSIX standard mandates awk. It does not mandate Perl or Python. <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/a...> <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/contents.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/c...> There are many systems which lack Perl or Python, but include awk. You might be carrying an Android device at the moment --- if you drop to its default userland, that provides a bunch of utilities, including awk, via Busybox. But not, so far as I'm aware, either Perl or Python. (You can of course install Termux which will then give you both Perl and Python, along with Node.js, ruby, and a whole slew of other scripting and compiled languages. But so long as we're considering stock installs, it's sed and awk.)
- paleface 3y agoSmall, embedded, busybox systems - per the parent comment.
- unmole 3y agoLike I said, MicroPython can run even on microcontrollers.
- anthk 3y agoOn wm's, why not a Z-machine? It's ideal for this.
- kqr 3y agoWhat would you suggest as an alternative to printing ASCII bar graphs? I do that all the time. Takes 20 seconds and often makes distributions, modalities, and patterns over time obvious right away.
- zimpenfish 3y ago`sparklines`[1] is good for an overall low-res view. `termgraph`[2] is sometimes better for a higher-res, more capable view (but can be finicky about the data.) [1] https://github.com/deeplook/sparklines https://github.com/deeplook/sparklines [2] https://github.com/mkaz/termgraph https://github.com/mkaz/termgraph
- kqr 3y agoBut both require depending on a third party library -- hardly something on a whim if ASCII bar charts do the job?
- llimllib 3y agognuplot is an alternative that is available on almost as many systems as awk, and can do the job as well edit: this prompted me to write up a little note showing how: https://notes.billmill.org/visualization/graphs/gnuplot/A_bar_graph_in_the_terminal_with_gnuplot.html https://notes.billmill.org/visualization/graphs/gnuplot/A_ba...
- dima55 3y agoIf you do this sort of thing more than once ever, look at the feedgnuplot tool (http://github.com/dkogan/feedgnuplot http://github.com/dkogan/feedgnuplot). It'll make your life easier
- llimllib 3y agoNeat! Once you're installing something to do terminal plots though, https://github.com/red-data-tools/YouPlot https://github.com/red-data-tools/YouPlot looks the nicest I've seen. (The nice feature of feedgnuplot of course is that you can _also_ render the plots to images, which youplot can't)