
Show HN: An eBook with hundreds of GNU Awk one-liners - asicsp
Hi,<p>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&#x27;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.<p>I made all my ebooks [2] free last month amidst the pandemic fears. These include GNU grep &amp; ripgrep, GNU sed and three books on regular expressions (Python, Ruby, JavaScript).<p>I&#x27;d appreciate your feedback and hope the books are useful. Happy learning :)<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;learn_gnuawk" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;learn_gnuawk</a><p>[2] <a href="https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;books&#x2F;" rel="nofollow">https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;books&#x2F;</a>
======
tannhaeuser
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
Agree 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_pu...](https://www.reddit.com/r/commandline/comments/fqkc6r/just_published_my_ebook_on_gnu_awk_free_for/flw0mtc/)

~~~
strenholme
The 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/aw...](https://pubs.opengroup.org/onlinepubs/009695399/utilities/awk.html)

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.

------
tyingq
Very 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.

~~~
obituary_latte
Very cool. Works on iOS with iSH surprisingly.

    
    
        FOUND index.html
        FOUND favicon.ico

~~~
tyingq
Oh wow. I wouldn't have guessed iSH would have packaged up the extensions I'm
using.

~~~
obituary_latte
Had to `apk add gawk` is all.

------
collyw
I 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.

~~~
mehrdadn
Have 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
re: why awk is almost always available, it's part of POSIX:
[https://pubs.opengroup.org/onlinepubs/009695399/utilities/aw...](https://pubs.opengroup.org/onlinepubs/009695399/utilities/awk.html)

------
Koshkin
This is great. Studying the work of masters is the best way to learn a trade.

------
GeorgeTirebiter
Thank you, even if publishing it at this time was somewhat Awk-ward...

~~~
asicsp
Yeah, 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
Purchased! Thank you for writing these. My wishlist is for a POSIX awk version
of your book.

------
serf
Very 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.

------
Congeec
Is there any equivalents of perl one-liners?

~~~
celias
no starch press sells a Perl One Liners book.
[https://nostarch.com/perloneliners](https://nostarch.com/perloneliners)

~~~
bewuethr
The 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)

------
davidcollantes
Thank you very much for this. My partner lost her job, and she will use your
books to help her on a new carrier path.

------
kbr2000
Tnx, that's nice. I like your 1 condition!

------
ojagodzinski
epub version will by available?

~~~
asicsp
Some 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-...](https://cmichel.io/how-to-create-beautiful-epub-programming-
ebooks/)

------
spsrich2
awk is great. Started using it in 1987, still using it in production today!

------
waynesonfire
you forgot to attach your amazon referral link!

~~~
asicsp
I 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.

------
kirubakaran
Clickable urls:

[https://github.com/learnbyexample/learn_gnuawk](https://github.com/learnbyexample/learn_gnuawk)

[https://learnbyexample.github.io/books/](https://learnbyexample.github.io/books/)

