Is it possible to convert strings to math operators?
someone <[email protected]> Wed, 15 Feb 2023 13:35:06 -0700
| Newsgroups | alt.comp.lang.awk |
|---|---|
| Organization | Ministry of Madness |
| Message-ID | <[email protected]> |
I didn't see anything in the gawk(1) manpage for doing this but it seems
like it should be possible.
ex. oz to lb using old-school units(1) command:
--
$ units -1 oz lb
* 0.0625
# this works:
$ echo "16 $(units -1 oz lb)" |awk '{print $1 " oz = " $1 * $3 " lb"}'
16 oz = 1 lb
# this does NOT work:
$ echo "16 $(units -1 oz lb)" |awk '{print $1 " oz = " $1 $2 $3 " lb"}'
16 oz = 16*0.0625 lb
--
Is there a way to tell (g)awk to interpret strings like "*", "/", "+",
"-", etc. as actual math operators?