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:
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.
More Articles by Anthony Lawrence © 2012-08-15 Anthony Lawrence
Unlike info, pinfo does not display anything if it has nothing. I've been forever irritated by info coming up with its default page when it has nothing to tell me. (Tony Lawrence)