Hey i have another query . I am trying to add all odd and even columns of the percentages calculated and adding them as columns to the left of the percentages. so in the above percenages calculated totoal odd would be ($1+$3....= 45.83+51.61...)
same thing for even as well
o
riginal input
55 65 48 45 48 68 32 68 44 34 88 65
82 63 52 54 51 68 75 0 0 20 10 77
55 77 60 55 22 60 40 25 75 55 45 90
20 80 33 63 0 64 32 22 75 0 43 56
54 54 12 35 48 87 65 12 77 85 0 15
calulated input
45.83 54.17 51.61 48.39 41.38 58.62 32.00 68.00 56.41 43.59 57.52 42.48
56.55 43.45 49.06 50.94 42.86 57.14 100.00 0.00 0.00 100.00 11.49 88.51
41.67 58.33 52.17 47.83 26.83 73.17 61.54 38.46 57.69 42.31 33.33 66.67
20.00 80.00 34.38 65.62 0.00 100.00 59.26 40.74 100.00 0.00 43.43 56.57
50.00 50.00 25.53 74.47 35.56 64.44 84.42 15.58 47.53 52.47 0.00 100.00
sample output:
t(odd) T(even)
313.28 315.22 45.83 54.16 51.61 48.38 41.37 58.62 32.00 68.00 ......
259.94 380.98 56.55 43.44 49.05 50.94 42.85 57.14 100.00 0
eggi found the solution to find the percentages of the original input (thanks again).....I was wondering if anyone could help me with this one..
can we use an arrary like this ???
array[j]
for (i = o,i <2000;,i++)
print i+2
for (j =1; j<2000)
print j+2
but i need to embed into the code :
awk 'BEGIN{lasti=1}{for (i=1;i<=NF;i++) {if ( i%2==0 ) {y=$lasti+$i;printf("%.2f %.2f ", $lasti/y*100, $i/y*100)}lasti=i }printf"\n" }'
PS: i need to embed the calulation code into any of this code.. THANK YOU IN ADVANCE
I also found a ksh code that does similar thing:
$ cat calc
#! /usr/bin/ksh
bc |&
print -p scale=2
exec < sample
while read line ; do
set -- $line
while (($#)) ; do
if (($1 + $2)) ; then
print -p "$1 * 100 / ($1 + $2)"
read -p result1
print -p "$2 * 100 / ($1 + $2)"
read -p result2
echo $result1 $result2 \\c
shift 2
else
echo 00.00 00.00 \\c
fi
done
echo
done
exit 0
$
$
$ ./calc