Awk is a very nice language with a very strange name. In this first article of a three-part series, start playing around with awk to see how it works and quickly get your awk programming skills up to speed. As the series progresses, more advanced topics will be covered, culminating with an advanced real-world awk application demo.
What can I say… Impressive
How far we’ll go like this?
(g)awk is a practical, relatively straightforward text processing language. I use it several times a week for ad-hoc processing / reporting (I work on a data warehouse project).
Note that there is a free gawk book available online:
http://www.gnu.org/software/gawk/manual/
————–
P.S. Nice little article from IBM, BTW.
Just out of curiosity, why are you posting this now, 8 years after it was put online? Did it show up in a recent feed or something (I notice that it said it was updated July 3, 2008, but I can’t imagine why — maybe some typo was fixed)?
Of course, it isn’t like awk has changed much in the last 8 years, I suppose And best of all, we don’t have to wait for the rest of the series, since it too was published 8 years ago:
http://www.ibm.com/developerworks/linux/library/l-awk2.html
http://www.ibm.com/developerworks/linux/library/l-awk3.html
And Daniel Robbins also wrote a series on sed, 9 years ago:
http://www.ibm.com/developerworks/linux/library/l-sed1.html
http://www.ibm.com/developerworks/linux/library/l-sed2.html
http://www.ibm.com/developerworks/linux/library/l-sed3.html
For a site with such an easily edited URL scheme, it sure does try to make it hard to find other articles in serieses or columns.
Suite, nicely linked
What the hell? To quote what ESR said about Awk in “The Art of Unix Programming” ( http://www.faqs.org/docs/artu/ch08s02.html#awk ):
{{{{{{{{{{
A case study of awk is included to point out that it is not a model for emulation; in fact, since 1990 it has largely fallen out of use. It has been superseded by new-school scripting languages^aEUR”notably Perl, which was explicitly designed to be an awk killer. The reasons are worthy of examination, because they constitute a bit of a cautionary tale for minilanguage designers.
The awk language was originally designed to be a small, expressive special-purpose language for report generation. Unfortunately, it turns out to have been designed at a bad spot on the complexity-vs.-power curve. The action language is noncompact, but the pattern-driven framework it sits inside keeps it from being generally applicable ^aEUR” that’s the worst of both worlds. And the new-school scripting languages can do anything awk can; their equivalent programs are usually just as readable, if not more so.
}}}}}}}}}}}
As someone who eats, lives and breathes Perl almost everyday, including for some “more serious” applications and APIs development, I find Awk to be incredibly limited, confusing, and kludgy. Perl is much more consistent, does not enforce awk’s line-based coding (though it can be added using some http://perldoc.perl.org/perlrun.html command line flags), and is a serious programming. So I’ve noticed that I’ve been using variations on “perl -e” instead of Awk (and instead of sed) instead.
Awk knowledge is useful in understanding other people’s old shell code, but it’s a stupid and old language that falls between the chairs and should be put to sleep. Just do yourself a favour and use Perl or Ruby or whatever.