From a90e497927d1faa4fcffbd1e9dbd46dcc20914c9 Mon Sep 17 00:00:00 2001 From: P2P-Next Date: Thu, 30 Jun 2011 13:19:01 +0300 Subject: [PATCH] Utils: 1-column-statistics added, which includes awk scripts that calculate min, max, avg, stdev for text files with one column of numbers --- Utils/1-column-statistics/avg | 15 +++++++++++++++ Utils/1-column-statistics/max | 16 ++++++++++++++++ Utils/1-column-statistics/min | 16 ++++++++++++++++ Utils/1-column-statistics/stdev | 17 +++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100755 Utils/1-column-statistics/avg create mode 100755 Utils/1-column-statistics/max create mode 100755 Utils/1-column-statistics/min create mode 100755 Utils/1-column-statistics/stdev diff --git a/Utils/1-column-statistics/avg b/Utils/1-column-statistics/avg new file mode 100755 index 0000000..5e6c40e --- /dev/null +++ b/Utils/1-column-statistics/avg @@ -0,0 +1,15 @@ +#!/usr/bin/awk -f +# Calculates the average value of 1 column. + +BEGIN { + sum = 0.0 + FS = "[ \t]+" +} + +/^[0-9]+/ { + sum += $1 +} + +END { + printf "%f\n", sum / NR +} diff --git a/Utils/1-column-statistics/max b/Utils/1-column-statistics/max new file mode 100755 index 0000000..8d7ae92 --- /dev/null +++ b/Utils/1-column-statistics/max @@ -0,0 +1,16 @@ +#!/usr/bin/awk -f +# Calculates the maximum value of 1 column. + +BEGIN { + max = log(0) + FS = "[ \t]+" +} + +/^[0-9]+/ { + if($1 > max) + max = $1 +} + +END { + printf "%f\n", max +} diff --git a/Utils/1-column-statistics/min b/Utils/1-column-statistics/min new file mode 100755 index 0000000..100df4d --- /dev/null +++ b/Utils/1-column-statistics/min @@ -0,0 +1,16 @@ +#!/usr/bin/awk -f +# Calculates the minumum value of 1 column. + +BEGIN { + min = -log(0) + FS = "[ \t]+" +} + +/^[0-9]+/ { + if($1 < min) + min = $1 +} + +END { + printf "%f\n", min +} diff --git a/Utils/1-column-statistics/stdev b/Utils/1-column-statistics/stdev new file mode 100755 index 0000000..87985d8 --- /dev/null +++ b/Utils/1-column-statistics/stdev @@ -0,0 +1,17 @@ +#!/usr/bin/awk -f +# Calculates the standard deviation of 1 column. + +BEGIN { + sum = 0.0 + sumsq = 0.0 + FS = "[ \t]+" +} + +/^[0-9]+/ { + sum += $1 + sumsq += $1 * $1 +} + +END { + printf "%f\n", sqrt(sumsq/NR - (sum/NR)**2) +} -- 2.20.1