I want a script to make awk to become an interactive mathematical calculator, to eval mathematical expressions given in each line.
I.e., instead of constructing awk commands to calculate expressions like the following:
$ awk 'BEGIN{print 180/1149}'
0.156658
$ awk 'BEGIN{print (150+141)/1149}'
0.253264
I want my script to take my mathematical expressions as input and do the calculation interactively. So the session will look like (alternative of input and output):
180/1149
0.156658
(150+141)/1149
0.253264
1 + 2
3
2 * 3 - 5
1
However I'm not able to do that myself:
$ awk '{print}'
180/1149
180/1149
^C
$ awk '{print $0}'
180/1149
180/1149
1 + 2
1 + 2
^C
If there is no simple solution to awk, what else, like perl?
Asked by xpt
(1858 rep)
Mar 24, 2023, 04:53 PM
Last activity: Mar 25, 2023, 12:00 PM
Last activity: Mar 25, 2023, 12:00 PM