At any Linux/Unix forum a large number of posts have to do with sed and awk - how do I do this, how do I do that?
I can see using sed. It's quick, it's simple (unless we are doing something complicated) and easy to learn. On the other hand, we have "awk", which is nasty and error prone even in its most basic invocations.
That's just my opinion, of course.
Sure, I used to use awk. When I used it, you weren't likely to find Perl on
most Unix systems, so for a lot of text mangling, awk was at least easier than writing in C or anything else. It did the job, and you'd get used to its quirks.
As Perl became ubiquitous, I thought of awk like something sticky you'd find under your car seat. Whatever use that thing may have had in the past, it's heading for the trash now. Why on earth would I suffer with awk's limitations and difficult synatx when I have Perl?
For me, awk synatx always seemed, well, awkward. Perl immediately
made sense to me. In a way, that's scary, because it could mean that my mind works like Larry Wall's mind, and if that wouldn't cause you to check in with a psychiatrist, I don't know what would.
I'm hardly alone in that opinion. Many of those forum questions end up
being answered by a Perl script. To me, the Perl solution always seems
easier to read and understand (that may just be my screwy mind, again).
Yet the forum questions persist. Some of it is homework: you can often tell when the petitioner includes such damning information as "I have to use awk. Can't use Perl" or forgets to delete instructions like "Show your work" when cutting and pasting. But it's not all homework: apparently a large number of people still use awk.
I went looking for why and found this: AWK Programming
. Some of the arguments made there in favor of awk include:
- awk is simpler (especially important if deciding which to learn
- awk syntax is far more regular (another advantage for the beginner,
even without considering syntax-highlighting editors)
- you may already know awk well enough for the task at hand
- you may have only awk installed
- awk can be smaller, thus much quicker to execute for small programs
- awk variables don't have `$' in front of them :-)
- clear perl code is better than unclear awk code; but NOTHING
comes close to unclear perl code
I'm not entirely in agreement - I don't think awk is "simpler" or has better syntax, but I can see that you could argue that. But even that page admits that "Generally Perl might be better for really complex tasks". I'd argue that awk is clumsy at complex tasks, but I definitely have to agree with that last comment about "unclear" code.
Probably many of the readers here used awk before discovering Perl. Did Perl win you over or do you still find yourself typing "awk" frequently? If you haven't used Perl, is it the learning curve? Or just that you can do whatever you need with the tools you already have?
Got something to add? Send me email.
Increase ad revenue 50-250% with Ezoic
More Articles by Anthony Lawrence
Find me on Google+
© 2012-08-15 Anthony Lawrence