CIS 201: Linux Shell Scripting

lewing@isc.tamu.edu

Gabelli School of Business, CIS Department

| CISWEB Doug White | RWU Main | White Hat Research | Email Doug | Access Data |

CIS 201: Lab 3

Data File: /dataFiles/lab3.dat

Data is a name followed by 10 times

For each of the people in the data file you need to figure out some information.

Process the data file to compute the following

Highest Average Speed for the 10 runs

Lowest Average Speed for the 10 runs

Single run fastest time // Don't do this unless you understand arrays.

Most consistent racer (lowest sd.)

Most erratic racer (highest sd.)

You pretty much have to use bc to compute standard deviation.

Basically take each run time (r) and subtract the mean time for the 10 runs (x) and square the result. Add all the times results together and divide by 10 (n). This is the variance. The square root of this is the SD.

SD will have to be done via BC in order to use any kind of accuracy; Here is a sample script which computes the SD for one item

#!/bin/ksh
#testing sd calculation
read name o1 o2 o3 o4 o5 o6 o7 o8 o9 o10 < /dataFiles/lab3.dat
avg=0
sum=0
(( sum=$o1+$o2+$o3+$o4+$o5+$o6+$o7+$o8+$o9+$o10 ))
(( avg=$(echo "scale=4 ; ($sum/10)" | bc) ))
echo $avg
sd=0
(( sd=$(echo "scale=8 ; sqrt((((($o1-$avg)^2+($o2-$avg)^2+($o3-$avg)^2+($o4-$avg)^2+($o5-$avg)^2)+($o6-$avg)^2+($o7-$avg)^2+($o8-$av
g)^2+($o9-$avg)^2+($o10-$avg)^2)/10))" | bc) ))
echo $sd

There are definitely ways to clean this up but this will get you started.

 

| Contact | © 2005 Secure Technology, LLC. |