Live data from Hacker News

Show HN: An eBook with hundreds of GNU Awk one-liners

news.ycombinator.com

41–50 of 51 posts

Re: Show HN: An eBook with hundreds of GNU Awk one-liners

#41
post #28

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.

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.

re: why awk is almost always available, it's part of POSIX: https://pubs.opengroup.org/onlinepubs/009695399/utilities/aw...

Re: Show HN: An eBook with hundreds of GNU Awk one-liners

#42
post #28

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.

It takes way less time to learn awk than perl.

Re: Show HN: An eBook with hundreds of GNU Awk one-liners

#43
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.

Re: Show HN: An eBook with hundreds of GNU Awk one-liners

#44

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

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).

Re: Show HN: An eBook with hundreds of GNU Awk one-liners

#45
post #28

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.

There is an available replacement for Python's standard re library, regex[1], which adds a long list of features and enhancements. It is too little known IMO, despite having existed and been continually maintained and enhanced for nearly a decade.

[1] https://pypi.org/project/regex/

Re: Show HN: An eBook with hundreds of GNU Awk one-liners

#46
post #28

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.

It takes way less time to learn awk than perl.

Yes, but I already know Perl. I assume more people know Perl than AWK, but maybe that's a bias from places I worked.

Re: Show HN: An eBook with hundreds of GNU Awk one-liners

#47
post #18

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 portabl…

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 yo…

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

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.

Re: Show HN: An eBook with hundreds of GNU Awk one-liners

#48

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 portabl…

Debian 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)

https://lists.debian.org/debian-user/2002/06/msg03020.html

Re: Show HN: An eBook with hundreds of GNU Awk one-liners

#49

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 portabl…

I 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]

Re: Show HN: An eBook with hundreds of GNU Awk one-liners

#50
post #26
post #25

Earlier quoted context omitted.

My 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.

> 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…

To be fair, /usr/bin/awk was mawk for a long time with Ubuntu. I remember getting in a heated discussion with GAWK’s maintainer that he should allow a way for [A-Z] to never match lower case letters (it does in some locales) so that we didn’t have to use stuff like [[:upper:]] and [[:lower:]], which do not work in mawk.
Post reply on HN