Live data from Hacker News

Why Learn Awk? (2016)

blog.jpalardy.com

21–30 of 246 posts

Re: Why Learn Awk? (2016)

#21
Hmm. I'm sure this question will induce a flamewar of practical "#NeverAwk"-ers fighting toolbelt bloat, versus tech-hoarding AWK apologists arguing against throwing something out given if fills .

Here's the thing: these arguments all too commonly focus on subjective notions of "simplicity", and toy examples divorced from actual common practise, and or solid comparable benchmarks.

Show me a range of practical examples, for each competing env (awk, sed, perl, python, ruby, maybe bash).

Include:

- time it takes to teach a total novice (the time it takes to learn whatever is needed that example, not the entire language)

- how easy it is to recall said knowledge at a later date

- how fast example is multiplied by how much you are likely to use it = actual time saved in terms of execution. for small, fast examples the difference is irrelevant, a 10x speedup that is 0.1s vs 0.01s is meaningless.

- how extendable an example is. Hence the original example should include a series of extensions to the original task, to demonstrate how flexible / composable they are: e.g. task 1) count lines in a file; task 2) count lines in a file, then add 42 to it;

I suspect awk falls behind in practicality vs perl (which can do simple one-liners, but also more complicated constructs), but perhaps has a hidden virtue wrt speed in more expensive tasks, ala https://news.ycombinator.com/item?id=17135841 or https://news.ycombinator.com/item?id=20293579

Re: Why Learn Awk? (2016)

#22
post #9

Because for some bizarre reason, "cut" doesn't ship with any decent column selection logic that is the equivalent of awk's $1, $2, etc., even in 2020. That's like 90% of my use of awk right there. I don't know of any easier equivalent of "awk '{ print $2 }'" for what it does. Posted partially so the Internet Correction Squad can froth at the mouth and set me straight, because I'd love to be showed to be wrong here.

The reason isn't that bizarre; it's a POSIX utility and must conform to the specification, which you can read here: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/c...

Surely we can infer that jerf would just say that it's bizarre for the POSIX specification to not include any easy way to get columns.

Re: Why Learn Awk? (2016)

#23
post #16
post #10

Awk, like shell, is a fraught programming environment, full of silent failure and hidden gotchas. Even for one-liners. I use shell because I have to, not because I like it. I dread maintaining shell scripts which have a bunch of awk and sed in them. The Unix ideal of small single-purpose tools and text processing is separable from these old warhorses.

scripts are the antithesis of modern software development. No Unit testing, No CI, no monitoring, no consistency, often no source control. Appeals to me as a hacker but only my scripts are intelligible - which is a bad sign. :)

I'm not actually convinced unit testing is all that valuable, unless the unit under test has a very clear input -> output transformation (like algorithms, string utilities, etc). If it doesn't (and most units don't), unit tests just encumber you.

Re: Why Learn Awk? (2016)

#24
post #5
post #2

Honorary mention of Taco Bell Programming. (fits this genre). http://widgetsandshit.com/teddziuba/2010/10/taco-bell-progra... Someone ought to write - Zen and the art of Unix tools usage.

>> suppose you have millions of web pages that you want to download and save to disk for later processing. How do you do it? I don't know enough about the 'real way' or the 'taco bell way', but interested to know --- is this doable the way Ted describes in the article via xargs and wget?

Yes, absolutely. This is absolutely how ~~we~~ many (most?) of us used to scrap web pages in the Dark Ages.

Re: Why Learn Awk? (2016)

#25
> Imagine programming without regular expressions.

I live in this future and it's beautiful.

Steps to programming without regular expressions:

1) find a PEG library for your language of choice

There is no step 2.

Re: Why Learn Awk? (2016)

#26
"Imagine programming without regular expressions."

Best of all worlds. I wish there would be a way to get back the time I spent with debugging edge cases of different regex implementations on various OS's.

Re: Why Learn Awk? (2016)

#27

Hmm. I'm sure this question will induce a flamewar of practical "#NeverAwk"-ers fighting toolbelt bloat, versus tech-hoarding AWK apologists arguing against throwing something out given if fills . Here's the thing: these arguments all too commonly focus on subjective notions of "simplicity", and toy examples divorced from actual common practise, and or solid comparable benchmarks . Show me a range of practical exampl…

I like to tell the story of when I was doing some genetics data wrangling and spent three days writing some perl code and I kept failing, then sent one of the researchers an email and he suggested an awk method and I turned 3 pages of perl into an awk one liner that works just fine. Now, its probably because I don't know perl very well, but as an ops type who doesnt have the classical dev/cs education, tools like it are my goto.

Re: Why Learn Awk? (2016)

#28
post #10

Awk, like shell, is a fraught programming environment, full of silent failure and hidden gotchas. Even for one-liners. I use shell because I have to, not because I like it. I dread maintaining shell scripts which have a bunch of awk and sed in them. The Unix ideal of small single-purpose tools and text processing is separable from these old warhorses.

While I agree that the silent failures and "opaqueness" can be off-putting, once you understand the tool and how to implement it in your workflow it is wonderfully efficient. Aside from being syntactically terse I haven't found any compelling reasons not to use it.

I've achieved a high level of expertise in Perl. Even though I can, I won't write complex Perl one liners; instead, I will write tested, documented utilities which someone who has not achieved such a level of mastery has a shot at grokking, maintaining and debugging.

Even better if I can write such utilities in a more modern programming language like Go or Rust, if the organization has personnel with expertise in such languages.

Re: Why Learn Awk? (2016)

#29

Why not just use Emacs for simple scripts and text manipulation? Way easier, lots of one liners as well, just as expressive.

Too big and slow. Also I disagree with the expressiveness, (emacs-has-chosen-a-very-longwinded 'way (to (express things))) that would be shorter in languages with more syntax.

Re: Why Learn Awk? (2016)

#30
post #12

I love awk, but I'm still waiting for the structural regex awk: http://doc.cat-v.org/bell_labs/structural_regexps/se.pdf

I just learned about SE a month or so ago, and it is indeed pretty awesome. I tried out the "vis" editor, using SE to create multiple cursors that I then manipulated with vi-like commands. That was a pretty sweet use case.
Post reply on HN