AWK equation evaluation.

Hi,

Is there a way to evaluate an equation contained in a string within an AWK script?

For example:
A = "(5*2)-1" (this equation is read from a file and varies line by line)

In this example, I can't see any way to get an answer of 9 unless I do:

cmd = "awk 'BEGIN{print "A"}'"
cmd | getline A

The above method works fine but it's rather slow when dealing with large files!

Does anybody know of a better way of achieving the same result within the main AWK script?

Any help and advice appreciated.

Steve

Hi.

Many interpreted languages have an eval feature, e.g. snobol, perl,.

I don't know of one for awk, but I'd be happy to learn of one ... cheers, drl

something educational to read up on....

Thanks for your help! The modified calc3 code does exactly what I want and is 15 times faster than the method I was using!