7 ms·
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 :)
[1] https://github.com/learnbyexample/learn_gnuawk https://github.com/learnbyexample/learn_gnuawk
[2] https://learnbyexample.github.io/books/ https://learnbyexample.github.io/books/
- tyingq 7y agoVery nice. I had cobbled up a "one liner" (sort of) gawk webserver on here a couple a months ago: https://news.ycombinator.com/item?id=22085459 https://news.ycombinator.com/item?id=22085459 I 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.
- asicsp 7y agoimpressive, if I use -o option to get a pretty printed version, it comes to 68 lines
- obituary_latte 7y agoVery cool. Works on iOS with iSH surprisingly. FOUND index.html FOUND favicon.ico
- tyingq 7y agoOh wow. I wouldn't have guessed iSH would have packaged up the extensions I'm using.
- obituary_latte 7y agoHad to `apk add gawk` is all.
- kbr2000 7y agoTnx, that's nice. I like your 1 condition!
- davidcollantes 7y agoThank you very much for this. My partner lost her job, and she will use your books to help her on a new carrier path.
- ojagodzinski 7y agoepub version will by available?
- asicsp 7y agoSome others have asked for an epub version too. I have this article [1] bookmarked, so if it goes well, I'll add epub as well this month. If you know pandoc, you could use the markdown source in the repo to generate a basic version and see if it works with your reader. [1] https://cmichel.io/how-to-create-beautiful-epub-programming-ebooks/ https://cmichel.io/how-to-create-beautiful-epub-programming-...
- Congeec 7y agoIs there any equivalents of perl one-liners?
- stevekemp 7y agoPerhaps something like this: https://gist.github.com/joyrexus/7328094 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.
- asicsp 7y agoI started with command line text processing repo [1] about three years back. That has a chapter on grep/sed/awk/perl/ruby one-liners along with many other tools. I may convert perl one-liners to a book as well later. [1] https://github.com/learnbyexample/Command-line-text-processing https://github.com/learnbyexample/Command-line-text-processi...
- celias 7y agono starch press sells a Perl One Liners book. https://nostarch.com/perloneliners https://nostarch.com/perloneliners
- bewuethr 7y agoThe book is based on this article series: https://catonmat.net/perl-one-liners-explained-part-one https://catonmat.net/perl-one-liners-explained-part-one
- waynesonfire 7y agoyou forgot to attach your amazon referral link!
- asicsp 7y agoI haven't published these books on amazon. The github repo has the links for leanpub/gumroad, they allow PDF which amazon doesn't as far as I know.
- Koshkin 7y agoThis is great. Studying the work of masters is the best way to learn a trade.
- kirubakaran 7y agoClickable urls: https://github.com/learnbyexample/learn_gnuawk https://github.com/learnbyexample/learn_gnuawk https://learnbyexample.github.io/books/ https://learnbyexample.github.io/books/
- tannhaeuser 7y agoI 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
- GeorgeTirebiter 7y agoThank you, even if publishing it at this time was somewhat Awk-ward...
- asicsp 7y agoYeah, these are troubling times for sure. I was about half way done with the book when things became serious in my country early March. I did think about delaying the release but then made the opposite decision. I made all my books free, released markdown sources for them and then published this book early (cutting down on some topics, no exercises yet, etc).
- jph 7y agoPurchased! Thank you for writing these. My wishlist is for a POSIX awk version of your book.
- collyw 7y agoI want a Perl one. I never saw the need to do AWK because I knew Perl fairly well. 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.
- Scarbutt 7y agoIt takes way less time to learn awk than perl.
- collyw 7y agoYes, but I already know Perl. I assume more people know Perl than AWK, but maybe that's a bias from places I worked.
- 7thaccount 7y agoThere is a perl oneliners book from nostarch press
- calvinmorrison 7y agohttp://www.mawode.com/~waltman/talks/one_liners.yapc11.pdf http://www.mawode.com/~waltman/talks/one_liners.yapc11.pdf
- mehrdadn 7y agoHave yet to learn Perl, but I've frequently not seen it preinstalled on systems, and additionally you sometimes need CPAN to be able to run scripts. awk might not be as powerful, but at least you know it's small, self-contained, and likely to be available in some form on most systems. That's part of its value I think... likely a consequence of not trying to do as much.
- anotheraccountf 7y agore: why awk is almost always available, it's part of POSIX: https://pubs.opengroup.org/onlinepubs/009695399/utilities/awk.html https://pubs.opengroup.org/onlinepubs/009695399/utilities/aw...
- spsrich2 7y agoawk is great. Started using it in 1987, still using it in production today!
- serf 7y agoVery cool. 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.