Note that there are some explanatory texts on larger screens.

plurals
  1. POCalculating the average each row and save into array
    primarykey
    data
    text
    <p>I'm trying to create the program to read each lines and calculate each line's average and store into array...For example, program will read first line, add all the numbers and divide by 24 to calculate the average which will be stored into Avg_list[1]. When I try to run the program, I encounter following error, I have no idea why it doesn't work... Can someone identify the problem?</p> <p>Code: in Ksh</p> <pre><code> c=0 while read -r line ; do v=$line set -- $v ((g=($2+$3+$4+$5+$6+$7+$8+$9+$10+$11+$12+$13+$14+$15+$16+$17+$18+$19+$20+$21+$22+$23+$24+$25+$26)/24)) echo $g Avg_list[${c}]=$g ((c=c+1)) done &lt; daily.txt </code></pre> <p>daily.txt</p> <pre><code>CPU 55 54 54 54 54 54 54 54 54 54 54 54 54 54 54 55 54 54 55 56 57 54 57 54 CPEAK 56 56 57 55 58 56 56 56 57 55 60 56 55 56 55 56 58 55 57 56 63 56 72 57 RAM 97 97 97 97 97 96 96 96 96 96 96 93 91 89 86 84 90 90 95 97 97 97 97 97 RPEAK 97 97 97 97 97 97 96 96 96 96 96 96 92 90 91 81 94 89 97 97 97 97 97 97 </code></pre> <p>Error note:</p> <pre><code>while read -r line ; do v=$line set -- $v ((g=($2+$3+$4+$5+$6+$7+$8+$9+$10+$11+$12+$13+$14+$15+$16+$17+$18+$19+$20+$21+$22+$23+$24+$25+$26)/24)) echo $g Avg_list[${c}]=$g ((c=c+1)) done &lt; daily.txt + 0&lt; daily.txt + read -r line + v=CPU 54 54 54 54 54 54 54 54 54 54 54 54 54 54 55 54 54 55 56 57 54 57 54 54 + set -- CPU 54 54 54 54 54 54 54 54 54 54 54 54 54 54 55 54 54 55 56 57 54 57 54 54 + (( g=(54+54+54+54+54+54+54+54+CPU0+CPU1+CPU2+CPU3+CPU4+CPU5+CPU6+CPU7+CPU8+CPU9+540+541+542+543+544+545+546)/24 )) PerformanceAM.sh[21]: g=(54+54+54+54+54+54+54+54+CPU0+CPU1+CPU2+CPU3+CPU4+CPU5+CPU6+CPU7+CPU8+CPU9+540+541+542+543+544+545+546)/24: 0403-009 The specified number is not valid for this command. </code></pre> <p>EDIT </p> <pre><code> while read -r line ; do v=$line set -- $v ((g=${2}+${3}+${4}+${5}+${6}+${7}+${8}+${9}+${10}+${11}+${12}+${13}+${14}+${15}+${16}+${17}+${18}+${19}+${20}+${21}+${22}+${23}+${24}+${25}+${26})/24)) echo $g Avg_list[${c}]=$g ((c=c+1)) done &lt; daily.txt </code></pre> <p>New error:</p> <p>while read -r line ; do v=$line set -- $v ((g=${2}+${3}+${4}+${5}+${6}+${7}+${8}+${9}+${10}+${11}+${12}+${13}+${14}+${15}+${16}+${17}+${18}+${19}+${20}+${21}+${22}+${23}+${24}+${25}+${26})/24)PerformanceAM.sh[18]: 0403-057 Syntax error at line 21 : `/24' is not expected.</p> <p>Thanks for your suggestions! when I tried used bracket i get this error...I'm now even more confused....it seems like it's not collecting numbers at all...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload