awk evaluating a string as a math expression

Hi,
I am writing a script in awk trying to replace strings that are math expressions with their result.
For example, I have a file that looks like this:

5-1
32/8-1
4*12
17+1-3

I would like to get the following output:

4
3
48
15

I tried doing it the following way (using the "bc" unix command):
Get the string into an awk variable and then send it to the shell.

The following line works (without using an input variable).
The outputVariable gets the correct answer "4".

"echo 5-1 | bc" | getline outputVariable;

So, I tried doing it like this:

"echo "inputVariable" | bc" | getline outputVariable;

This, of course, does not work.

I tried printing it to a file and then taking the string from a file:

print inputVariable > "./temp"
"tail -1 ./temp | bc" | getline outputVar

This does not work either.

I am out of ideas.

P.S
I did not come up with any way to transform the string into a math expression that awk can process internally (without going to shell).
Maybe there's a way, and this can be a good solution for me.

Thank you for your help.

while read line;do echo $(($line));done < infile
4
3
48
15

Sorry,
I don't understand.

perl solution

$ cat file
5+1
5*9
6/4
7-1

$ cat file | perl -nle 'print eval($_)'
6
45
1.5
6

OK guys.
I am sorry, I did not make my question clear enough.
My file does not look so simple, it is more complex.
Here's the real input:

wire        [32-1:0]       jerry_AWADDR;
wire                       jerry_AWVALID;
wire         [4-1:0]       jerry_AWCACHE;
wire         [4-1:0]       jerry_AWID;
wire         [4-1:0]       jerry_AWLEN;
wire         [2-1:0]       jerry_AWLOCK;
wire         [3-1:0]       jerry_AWPROT;
wire         [3-1:0]       jerry_AWSIZE;
wire         [2-1:0]       jerry_AWBURST;
wire        [64-1:0]       jerry_WDATA;
wire         [4-1:0]       jerry_WID;
wire                       jerry_WLAST;
wire         [8-1:0]       jerry_WSTRB;
wire                       jerry_WVALID;
wire                       jerry_BREADY;

Now, I would like to make it look like this:

wire        [31:0]       jerry_AWADDR;
wire                       jerry_AWVALID;
wire         [3:0]       jerry_AWCACHE;
wire         [3:0]       jerry_AWID;
wire         [3:0]       jerry_AWLEN;
wire         [1:0]       jerry_AWLOCK;
wire         [2:0]       jerry_AWPROT;
wire         [2:0]       jerry_AWSIZE;
wire         [1:0]       jerry_AWBURST;
wire        [63:0]       jerry_WDATA;
wire         [3:0]       jerry_WID;
wire                       jerry_WLAST;
wire         [7:0]       jerry_WSTRB;
wire                       jerry_WVALID;
wire                       jerry_BREADY;

I hope this makes it clearer.

Thank you.

This bash script
while read line;do echo $(($line));done < infile
reads the expression from the file, evaluate it and then print the result.
If you give us some clue of what the goal is, we could give more help.

awk -F "[:[]" '/:/{"echo $(("$2"))"|getline var;$2="[" var ":"}1' OFS= infile

It did not work for me.
I am getting blanks where the evaluated number should be.
Are you running a certain version of awk?

Thank you.

---------- Post updated at 06:45 AM ---------- Previous update was at 05:08 AM ----------

This does not work for me.
I am getting blanks where the evaluated number should be:

wire        [:0]       jerry_AWADDR;
wire                       jerry_AWVALID;
wire         [:0]       jerry_AWCACHE;
wire         [:0]       jerry_AWID;
wire         [:0]       jerry_AWLEN;
wire         [:0]       jerry_AWLOCK;
wire         [:0]       jerry_AWPROT;
wire         [:0]       jerry_AWSIZE;
wire         [:0]       jerry_AWBURST;
wire        [:0]       jerry_WDATA;
wire         [:0]       jerry_WID;
wire                       jerry_WLAST;
wire         [:0]       jerry_WSTRB;
wire                       jerry_WVALID;
wire                       jerry_BREADY;

Which version of awk are you using?

Thank you.

avi.levi,
check this out:

$ awk -F "[:[]" '{x[NR]=$1;y[NR]=$3;cmd="echo "$2"|bc";(cmd|getline a[NR]);close(cmd)}END{for(i=1;i<=NR;i++) print x,"[" a ":" y}' file|awk -F";" '{print $1";"}'
wire         [31:0]       jerry_AWADDR;
wire                       jerry_AWVALID;
wire          [3:0]       jerry_AWCACHE;
wire          [3:0]       jerry_AWID;
wire          [3:0]       jerry_AWLEN;
wire          [1:0]       jerry_AWLOCK;
wire          [2:0]       jerry_AWPROT;
wire          [2:0]       jerry_AWSIZE;
wire          [1:0]       jerry_AWBURST;
wire         [63:0]       jerry_WDATA;
wire          [3:0]       jerry_WID;
wire                       jerry_WLAST;
wire          [7:0]       jerry_WSTRB;
wire                       jerry_WVALID;
wire                       jerry_BREADY;