Functions in awk

Functions in awk

Post by Denni » Mon, 16 Apr 2001 02:58:09



Is it possible to have functions on awk. If it is could anyone give me an
example on how to use it.
Thanks
 
 
 

Functions in awk

Post by Bill Marcu » Mon, 16 Apr 2001 09:36:06



>Is it possible to have functions on awk. If it is could anyone give me an
>example on how to use it.

Yes it is possible, unless you use an old awk like the one in Solaris.
If you are in Solaris, use nawk, not awk.  The man page should say
something about functions.

 
 
 

Functions in awk

Post by Anthony Borl » Mon, 16 Apr 2001 08:51:40



Quote:> Is it possible to have functions on awk. If it is could anyone give me an
> example on how to use it.
> Thanks

A simple 'awk' program using user-defined functions:

function myFunction(string)
{
  print "Hi there";
  print string;
  print "Bye there";

Quote:}

END {
  myFunction("A little message for you");

Quote:}

I hope this helps.
 
 
 

Functions in awk

Post by Peter S Tillie » Mon, 16 Apr 2001 16:47:17




> >Is it possible to have functions on awk. If it is could anyone give me an
> >example on how to use it.

> Yes it is possible, unless you use an old awk like the one in Solaris.
> If you are in Solaris, use nawk, not awk.  The man page should say
> something about functions.

Even better: on Solaris use the awk in /usr/xpg4/bin/awk if you have it
because it is POSIX compliant.  The other awk and nawk on Solaris are very
old pre-1989 and ~1989 respectively.

HTH
--



Opinions expressed are my own and not necessarily those of my employer.