Hi, I am trying to multiply column#1 with column#2 using a shell script. How can I make a for-loop script using 1st column as "i" and the second column as "j" from the following file? Please feel free to share any alternative ways to multiplying column#1 with column#2.
---------- Post updated at 08:20 PM ---------- Previous update was at 08:16 PM ----------
This is what I tried..... but did not work
root@vna1(/)# for x in `awk '{print $1}' /tmp/temp6`
> do
> for j in `awk '{print $2}' /tmp/temp6`
> do
> echo "scale=3; $x * $y" | bc
> done
> done
syntax error on line 1 stdin
syntax error on line 1 stdin
syntax error on line 1 stdin
syntax error on line 1 stdin
syntax error on line 1 stdin
syntax error on line 1 stdin
syntax error on line 1 stdin
---------- Post updated at 02:28 PM ---------- Previous update was at 11:53 AM ----------
The output column in the solution above can have any number of values.... how can all those values be added when I we do not know the number of fields in the output?
After adding up the two columns with rdcwayx's command, I had the output in form of one column. That column can have 15,16 or any number of values. My question was how to get the sum of all those values.
For example:
Output:
12
5
8
10
I want to get the sum of the values: 12+5+8+10=35. But I do not know how many values will be in the output, because output is different on each server.