Just picked this up from my favorite site: commandline-fu.

$ awk '{delta = $1 - avg; avg += delta / NR; mean2 += delta * ($1 - avg); } END { print sqrt(mean2 / NR); }'

Let’s test it by finding the standard deviation of 1, 2, 3, 4, and 5 whose standard deviation is sqrt(2): in BASH, pipe in the out put of the following (which just echoes out numbers from 1 through 5) to the above command to find that it is in fact sqrt(2) or 1.42421

`$ for n in {1..5}; do echo $n; done`

### Like this:

Like Loading...

*Related*

simonvpe

said:Interesting how you used another algorithm to do that. I just made a simple awk tutorial today and used standard deviation calculations to show off how to use associative arrays. It’s an approximation so not completely true but I might want to mention your calculation too for the sake of clarity.

Have a look at it at http://simonslinuxworld.blogspot.com/2012/04/awk-tutorial-by-example.html