4 ms·
I always like when classic lean-and-mean Unix tools get attention, as opposed to big language ecosystems. Speaking of which, is there a particular reason why on
by tannhaeuser 7y ago
I always like when classic lean-and-mean Unix tools get attention, as opposed to big language ecosystems. Speaking of which, is there a particular reason why only gawk is covered? gawk has only very minor enhancements to POSIX awk, and gawk isn't even the default in many place. For example, Debian uses, or used to use, mawk as default, while the BSDs and Mac OS have nawk. I think the point of awk is that it's portable, and introducing gawkisms in your program not only makes it non-portable, but also would make it impossible to run on mawk, which is much much faster for eg. log file analysis. Might not matter all that much for one-liners, though.
- asicsp 7y agoAgree about portability issues. I cover only gawk, because I don't know all the differences between various versions. This started as a chapter in my command line text processing repo, where I cover various tools. I had come across various posts on stackoverflow/unix.stackexchange about implementation differences. I use Ubuntu, so I made a choice of sticking to GNU/Linux to make my life simpler. I'm not sure about your point saying "only very minor enhancements". When I posted about my book on reddit, I got this comment [1] noting feature differences. [1] https://www.reddit.com/r/commandline/comments/fqkc6r/just_published_my_ebook_on_gnu_awk_free_for/flw0mtc/ https://www.reddit.com/r/commandline/comments/fqkc6r/just_pu...
- strenholme 7y agoThe way to see if something works in AWK is to read the 2004 Open group POSIX standard on it: https://pubs.opengroup.org/onlinepubs/009695399/utilities/awk.html https://pubs.opengroup.org/onlinepubs/009695399/utilities/aw... Here’s my AWK (OK, shell + AWK) one liner: while echo -n '] ' ; do read a; awk 'BEGIN{print '"$a"'}' ; done It’s a calculator; type in something like 2 + 2 and it will give you 4. Since standard AWK has advanced math functions like log, it’s a full blown scientific calculator. The only tricky part is that you hit Ctrl + C (not Ctrl + D) to exit it.
- kick 7y agogawk is pretty much everywhere now that awk sees substantial use, and presents rather great enhancements over POSIX awk[1]. I usually don't think that GNU tools make much sense to focus on, but gawk is something that's, generally-speaking, worth doing so. Especially given that it runs on almost everywhere under the sun. [1] http://www.skeeve.com/awk-sys-prog.html http://www.skeeve.com/awk-sys-prog.html
- oefrha 7y ago“It runs everywhere” (gawk) is very different from “it’s installed out of box everywhere” (awk). The latter can be used in provisioning scripts, shell script libraries/modules, etc. where the former usually can’t. (Not saying gawk isn’t significantly better than awk for some tasks.)
- kick 7y agoMy claims were that GNU awk is everywhere that awk sees substantial use, and that it runs everywhere. These were two separate claims, and are very different. It is very rare that you see a system that awk is frequently used on that doesn't have GNU awk installed.
- oefrha 7y ago> It is very rare that you see a system that awk is frequently used on that doesn't have GNU awk installed. Wait, what? Ubuntu server and macOS both have awk preinstalled (which is true for any POSIX) and gawk not preinstalled. Those are what I (and many other developers) spend 95% of my time on. And I do use awk frequently. Edit: Okay, /usr/bin/awk is actually gawk on Ubuntu, so I was wrong about that. Still, macOS isn't very rare.
- kick 7y agoHow many OS X users do you think are actively using awk in any of its variants? What percentage of total awk usage is on OS X, do you think? OS X may not be rare, but it seems highly unlikely that many OS X systems see frequent usage of awk.
- gridlockd 7y agoI don't see Unix tools as lean and mean, but as brittle and slow. It's never just a "one liner", you end up piping text data through dozens of programs with inconsistent unstructured interfaces. I don't understand the reverence for these tools. I think it's a bunch of junk that somehow can't get replaced because it's not quite bad enough and it's "already installed" everywhere.
- deleted 7y ago[deleted]
- Mediterraneo10 7y agoDebian Stable runs GNU Awk. Issuing the command awk --version gives the output: GNU Awk 4.2.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.1.2)
- tannhaeuser 7y agohttps://lists.debian.org/debian-user/2002/06/msg03020.html https://lists.debian.org/debian-user/2002/06/msg03020.html