Live data from Hacker News

Awk: The Power and Promise of a 40-Year-Old Language

fosslife.org

61–70 of 122 posts

Re: Awk: The Power and Promise of a 40-Year-Old Language

#61

Earlier quoted context omitted.

The biggest reason to learn AWK, IMO, is that it's on pretty much every single linux distribution. You might not have perl or python. You WILL have AWK. Only the most minimal of minimal linux systems will exclude it. Even busybox includes awk. That's how essential it's viewed.

I'm curious what linux distros don't have either some version of perl or python. I like awk, mind, but this is not necessarily (IME) a good argument for it.

Anything busybox-based. I'm not sure busybox awk is very complete, either.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#62
post #56

Earlier quoted context omitted.

Probably as much for legacy reasons as anything else. Perl was the chosen scripting language for utilities, it works, they understand it, and they've kept with it. Sort of how they stay with CVS for their source repository. Python isn't even installed on a base OpenBSD system.

Mark Espie rewrote the entire package system in perl in 2010, which is a bit late to be classed as legacy. https://undeadly.org/cgi?action=article;sid=20100323141307 I'm not sure what was used for the version before this, but the original BSD package system was written in C.

But perl was already the "standard" for other system/config utilities, no?

Re: Awk: The Power and Promise of a 40-Year-Old Language

#63
post #60
post #58

Earlier quoted context omitted.

It does not. The pipe command leaves the pipe open and successive pipes with identical strings remain open until the pipe is explicitly closed. [edit] Here's the link to the gawk documentation, but most flavors of AWK work similarly: https://www.gnu.org/software/gawk/manual/gawk.html#Close-Fil...

Wow, this is amazing. It really shows how complexity should be managed in the tool so that the user can do the naive thing and have it be accidentally optimal

It is surprising to people who expect them to behave like shell pipelines and redirections though. I somehow never got bit by it, but have definitely corrected other's awk scripts who didn't know about this feature.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#64

Earlier quoted context omitted.

The biggest reason to learn AWK, IMO, is that it's on pretty much every single linux distribution. You might not have perl or python. You WILL have AWK. Only the most minimal of minimal linux systems will exclude it. Even busybox includes awk. That's how essential it's viewed.

I'm curious what linux distros don't have either some version of perl or python. I like awk, mind, but this is not necessarily (IME) a good argument for it.

You'll find this a lot in the embedded space. As well, you'll see a bunch of docker images that don't have perl/python.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#65
post #23

Earlier quoted context omitted.

I had to take large CSV files like {question, right_ans, wrong_ans1, wrong_ans2, wrong_ans3} and covert them into SQL insert files. Few caveats - some could be duplicates, some characters were not allowed, and some had formatting issues. The first issue was avoided by upserting, but the other two I used Awk and Sed for and put together a fairly robust script far quicker than if I reached for Python. I probably would…

"""I probably would have reached for Python if I realised how many edge cases there were""" This is the counter for all the "success" stories of awk users that walked away with an underspecced and underdeveloped 5 minute solution.

Most people reach for what they know best. I'm not sure it really proves anything about relative merits.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#66

Earlier quoted context omitted.

The biggest reason to learn AWK, IMO, is that it's on pretty much every single linux distribution. You might not have perl or python. You WILL have AWK. Only the most minimal of minimal linux systems will exclude it. Even busybox includes awk. That's how essential it's viewed.

I'm curious what linux distros don't have either some version of perl or python. I like awk, mind, but this is not necessarily (IME) a good argument for it.

> I'm curious what linux distros don't have either some version of perl or python.

I imagine that DamnSmallLinux or TinyCoreLinux possibly don't have them by default. Their focus is to be as small as possible in order to download quickly and fit in a USB drive or CD. Their small size was more important back when speeds were slower and drives were smaller. They were also good for when you had a limited number of storage options and you wanted the running OS to fit completely in RAM (back when RAM was smaller).

Re: Awk: The Power and Promise of a 40-Year-Old Language

#67

Earlier quoted context omitted.

The biggest reason to learn AWK, IMO, is that it's on pretty much every single linux distribution. You might not have perl or python. You WILL have AWK. Only the most minimal of minimal linux systems will exclude it. Even busybox includes awk. That's how essential it's viewed.

I'm curious what linux distros don't have either some version of perl or python. I like awk, mind, but this is not necessarily (IME) a good argument for it.

The POSIX specification includes awk, but not perl or python. The world of UNIX and UNIX-likes is larger than just Linux distributions. Depending on the utility you plan on building and the platforms you expect it to run on, it may be wiser to reach for awk than other PLs.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#68

I never use Awk until last year. I wanted to monitor an embedded device with little more than bustbox and python on it. There was quite a bit of information in the log files (I had already written a custom log file viewer with some highlighting) but I wanted to monitor in real-time. Somehow I decided to use Awk to monitor the tail of the log file and do realtime bar-graphs by generating appropriate cursor control seq…

The biggest reason to learn AWK, IMO, is that it's on pretty much every single linux distribution. You might not have perl or python. You WILL have AWK. Only the most minimal of minimal linux systems will exclude it. Even busybox includes awk. That's how essential it's viewed.

Something fun in that regard, speaking of minimal...the TRS-80 Color Computer community now has a version of awk that runs on NitrOS-9, a variant of OS-9/6809 originally written for the Hitachi 6309. (64K address space, no separate I and D space.)

Re: Awk: The Power and Promise of a 40-Year-Old Language

#69
post #5

i no longer use it but Perl was always the better solution when one thought AWK was the answer. Perl will do those things where AWK really shines and if the problem got bigger, Perl was easier to deal with.

The problem is that awk is a very simple language, which you can learn in an afternoon. Perl is a very complex language, and is not used anymore, so you're just spending your time on something you'll rarely use.

It's used in Debian system tools and in Git, so it's still in wide use.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#70
post #37

Earlier quoted context omitted.

Ehh. Until the 'job' gets extended and then your simple tool makes it exponentially more complex and you have to rewrite it with the more powerful tool.

Choosing a "good enough for the medium term with minimal effort now" is a winner in my book, even if it's likely to be rewritten in the long term.

Exactly. I end up re-implementing my scripts if they outgrow the original scripting language anyway, because it's a good time to add proper argument and error handling, logging, etc.
Post reply on HN