A little Awk

Greg Grothaus posted an article today entitled Why you should learn just a little Awk. The article recommends taking a few minutes to learn only the most basic parts of the Awk language. I find this interesting for several reasons.

First, it is impressive what you can accomplish with just a few keystrokes in Awk. The language was designed for file munging and it does this very well. Many people, myself included, think of Perl as a language for file munging. And so it is, but I remember reading something from Larry Wall, creator of Perl, saying that he uses Awk for some tasks.

Second, Grothaus isn’t encouraging people to master the language. He’s saying to just learn a handful of features, at least to start. That goes against my grain. When I learn a language, I want to learn it thoroughly. On the other hand, I don’t have the time or energy lately to learn a new language on top of everything else I have going on. But I think Grothaus has a good point: if you just take a few minutes to learn only how to do several very specific tasks, it could be worth it.

Finally, I found it interesting to read a blog post about a language I haven’t touched in well over a decade. I used Awk in grad school for a little while, and was quite impressed with it. But someone suggested that Perl was similar but even better and I dropped Awk for Perl. Looking back I’d say Perl is more general than Awk, but not necessarily better.  Awk is quite good at the kinds of tasks it was designed for.

I’ve been trying to consolidate the list of programming languages I use after reaching programming language fatigue. Adding yet another language to the list of languages I haven’t mastered but use occasionally would not be progress. But Grothaus’ article tempts me to look at Awk again, not with the intention of mastering it but rather to learn how to do just a small number of things it does remarkably well.

Related posts

5 thoughts on “A little Awk

  1. I had pretty much the same reaction to Grothaus’ article. I spent about an hour playing with Awk and thinking I might just want to do some more. A little Awk goes a long way.

    Next thing I knew, I had ordered a (used!) copy of The Awk Programming Language from Amazon.

  2. I tend to use awk for the very use cases Greg suggests and I am very happy with it. It makes for nice shell one-liners mostly. A big advantage in this scenario is speed; awking a gigabyte of text is soooo much faster than doing the same with a perl expression on the shell.

  3. I love ask – tho I always use gawk because the syntax errors messages are better.

    What I find fascinating is how related it is to the eventbased programming styles you can do with last. And First. In SAS datasteps.
    I love the sense of being able to say print $NF to get the last field.
    And As you say it is fast. I wrote a Sas log checker which does 250000 lines in about 0.1 secs on my Mac cube ( 10 years old next month :-)

    I have some examples at daveg.tiddlyspot.com for anyone looking for starters.

Comments are closed.