awk, mawk, gawk - which is "better"?
I'm thinking that awk is most likely to be the most ubiquitous and hence is better to use. Am I right in thinking that it's better to use awk than any other flavours?
|
Hya,
It all depends what you want to do. If only you use your code on your comp (penguin, apple, solaris, hp or whatever) it is your choice. If you want to circulate your code, compatibility is another issue. (also true, when you have many hardwares.) Happy Penguins! |
Hi.
Yes, awk is the name that is generic. However, I am told that awk on Solaris is the verrry old awk, and that most knowledgeable people use nawk on that platform. It is often said that mawk is faster than the others. The gawk probably has the best documentation. I'd probably stay with awk, and put a comment to use nawk on Solaris (in fact, that is what I do): Code:
# Use nawk or /usr/xpg4/bin/awk on Solaris. |
History lesson I'm afraid, then you will be able to decide for yourself which is the more appropriate depending on circumstances.
Originally the language was called awk. In approx 1989 nawk (new awk) superseded awk and later gawk (Gnu awk) extended the langauge further. So simple, use gawk! Not so fast. If you use Solaris then you will probably find that you are limited to what is installed by default, unless you have a very progressive sysadmin that has installed gawk, but probably not. Solaris normally has installed both awk and nawk. The original awk will give errors if you try to use floating point numbers and in retrospect is severely short of really useful features. So the answer on Solaris is to use nawk. Now on other distros either because of symlinking or otherwise (I'm hedging my bets here because I'm moving away from my home turf) nawk or gawk are refered to as awk, but not universally so. Windows - just don't go there with awk, you will end up dissapointed. |
An additional monkey wrench in the works.
The awk program is named after its authors, Alfred Aho, Peter Weinberger and Brian Kernighan all at the time of AT&T Bell Laboratories. The original awk dates from a long, long time ago (1977). New awk was released in conjunction with Aho et. al. The AWK Programming Language (Redding, MA: Addision-Wesley Publishing Co., 1988), ISBN 0-203-07981-X. New AWK, called nawk, is completely documented in this book. As to the differences, the preface, pp. v-vi briefly outlines: Quote:
My own experience has been that going from Linux to Solaris can sometimes be a royal pain where you sit and I have learned (the hard way, as usual) to avoid GNU-specific enhancements to any language implementation, not just AWK. I have the source code for nawk and run it on my Linux boxes just to avoid those kind of problems and life is better. Is there any "best?" Well, best is a relative term. In my book, best means no problems porting high-level software from one platform to another and that means avoiding enhancements because they will always come back and bite you in the butt (that was learned the hard way porting DEC FORTRAN programs -- chock full of DEC's enhancements -- to System V). If you find a copy of the book and adhere to the grammar and syntax therein you'll probably not have a problem with gawk on Linux and nawk on Solaris. Personally, on Solaris, I write in nawk grammar and syntax to take advantage of the authors' enhancements from oawk; and, you probably won't have gawk available on a Solaris box out of the carton (system administrators where I get paid are really leery of wily-nilly installing GNU utilities because of past compatibility problems that nobody really wants to spend time dealing with when an analog is sitting there to begin with). For what it's worth... |
It's worth a lot. I have the book - if I can find it - and believe me, it isn't really very thick and that can't be said for most languages. If you are sticking with nawk (1989), then it's exceedingly handy to have it to hand on the desk.
|
Quote:
|
Quote:
on the same hardware in the better OS. Performance-wise, that is; the functionality is obviously the same. I've done a bit of testing about a year ago, and the run-times, specially for larger files, sucked real badly in comparison. Cheers, Tink |
Quote:
hope one year from that time, things have been done to address this. How about compiling the source on windows? |
All times are GMT -5. The time now is 05:50 PM. |