Show HN: An eBook with hundreds of GNU Awk one-liners
Hi,
I recently published my ebook on GNU awk one-liners [1]. It starts from the basics of awk syntax and then discusses one-liner examples. There's a chapter on regular expressions as well. The github repo has the details on how to get the PDF version, all the example files and code snippets used in the book, sample chapters as well the markdown source used to generate the PDF.
I made all my ebooks [2] free last month amidst the pandemic fears. These include GNU grep & ripgrep, GNU sed and three books on regular expressions (Python, Ruby, JavaScript).
I'd appreciate your feedback and hope the books are useful. Happy learning :)
50 comments
[ 3.3 ms ] story [ 123 ms ] threadI tried making it scalable, but unfortunately, the server sockets in gawk don't set SO_REUSEPORT. So, I can't fork usable children. It does work if you use LD_PRELOAD tricks, or edit the gawk binary to change SO_REUSEADDR to SO_REUSEPORT, but both are pretty hacky.
If gawk would separate the listen() and accept() calls out, you could do a lot more with their server socket code.
[1] https://cmichel.io/how-to-create-beautiful-epub-programming-...
https://gist.github.com/joyrexus/7328094
The thing about cookbooks is that you rarely find something that matches what you need in the moment - you really need to learn and use these tools regularly and then you'll be prepared without documentation.
[1] https://github.com/learnbyexample/Command-line-text-processi...
https://github.com/learnbyexample/learn_gnuawk
https://learnbyexample.github.io/books/
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_pu...
https://pubs.opengroup.org/onlinepubs/009695399/utilities/aw...
Here’s my AWK (OK, shell + AWK) one liner:
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.
[1] http://www.skeeve.com/awk-sys-prog.html
(Not saying gawk isn’t significantly better than awk for some tasks.)
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.
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.
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.
GNU Awk 4.2.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.1.2)
In saying that the youngsters should learn some of these old school tools. Python is a nice language but the regexes are crap acompared to Perl. I always need to look up the documentation. Perls are built in, clean and concise.
(caturing, groups) = string =~ /regex/
I remember that having not touched Perl in a while. I miss it.
Python's default 're' module does indeed lack many features, but there's 'regex' third party module that would be easier to adapt for perl users.
[1] https://github.com/learnbyexample/Command-line-text-processi...
[1] https://pypi.org/project/regex/
I have the Bash equivalent (sorta) on my bookshelf and has seen a lot of use. ('GNU Introduction to the Command-Line').
It introduces a command, describes the options in detail, and then the next few pages for each command are useful bash (mostly) one-liners.