awk assistance

bscott at ntisys.com bscott at ntisys.com
Wed Nov 13 20:28:49 EST 2002


On Wed, 13 Nov 2002, at 1:03pm, pll at lanminds.com wrote:
> I'd argue that 'awk' is "The Old Way" and has been replaced by Perl as
> "The Way" :)

  Generally true, I expect, but there are still reasons to use awk.  One
reason is if one has to deal with lots of crufty old Unix systems that don't
have Perl (not an ideal situation, of course, but life is often less than
ideal).  Another is if one is writing a shell script that must work even if
Perl is not installed (seems like a strange idea, yes, but believe it or
not, Perl is not part of the kernel (neither is Emacs)).  Perl is also
unavailable if /usr is not mounted, which can be significant if you are an
initscript.

  But, again, what you say is generally true.  I'm just picky.  :-)

> Awk has a lot of limitations which don't exist in perl, like line length
> (1024 characters?), etc.

  FWIW, I believe gawk has removed many of those.  Of course, if you've got
the GNU tools, there is little reason not to have Perl, too.  :)

  Also FWIW, this awk code

	awk -F/ '{ print $NF }'

appears to run about 4 times faster than this Perl code

	perl -F'/' -ane  'print "$F[$#F]";'

, at least in my quick tests.  I mention this out of curiosity more than
anything else; I highly doubt the performance difference could ever matter
in practice.

-- 
Ben Scott <bscott at ntisys.com>
| The opinions expressed in this message are those of the author and do not |
| necessarily represent the views or policy of any other person, entity or  |
| organization.  All information is provided without warranty of any kind.  |




More information about the gnhlug-discuss mailing list