Created
September 24, 2016 16:54
-
-
Save seadog007/15ffbe6d473770e28f430e91c4bceb02 to your computer and use it in GitHub Desktop.
Moving Avg. (Rolling Mean) Bash Demo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function gendata(){ | |
for i in `seq 1 $1` | |
do | |
echo $(( ( RANDOM % $2 ) + 1 )) >> data_$$ | |
done | |
} | |
echo '##Generate Datas##' | |
gendata 5 10 | |
cat data_$$ | |
echo '##Calculate Rolling Avg.##' | |
amount=0 | |
count=0 | |
while read line | |
do | |
amount=$(($amount + $line)) | |
count=$(($count + 1)) | |
python -c "print $amount/$count.0" | |
done < data_$$ | |
rm data_$$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment