Created
April 22, 2020 19:43
-
-
Save wbbradley/9d3e8d19682421eaf6dad63001b8addb to your computer and use it in GitHub Desktop.
This file contains 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
function column-sum() { | |
column=$1 | |
delim=${2:-','} | |
awk -F "$delim" ' | |
BEGIN { sum=0 } | |
{ sum += $'"$column"' } | |
END { print sum } | |
' | |
} | |
function column-only-above() { | |
column=$1 | |
limit=$2 | |
delim=${3:-','} | |
awk -F "$delim" ' | |
{ if ($'"$column"' >= '"$limit"') print } | |
' | |
} | |
function column-only-below() { | |
column=$1 | |
limit=$2 | |
delim=${3:-','} | |
awk -F "$delim" ' | |
{ if ($'"$column"' < '"$limit"') print } | |
' | |
} | |
function column-only-between() { | |
column=$1 | |
low=$2 | |
high=$3 | |
delim=${4:-','} | |
awk -F "$delim" ' | |
{ if ($'"$column"' < '"$high"' && $'"$column"' >= '"$low"') print } | |
' | |
} | |
function column-avg() { | |
column=$1 | |
delim=${2:-','} | |
awk -F "$delim" ' | |
BEGIN { sum=0; count=0 } | |
{ sum += $'"$column"'; count += 1 } | |
END { print sum/count } | |
' | |
} | |
function column-max() { | |
column=$1 | |
delim=${2:-','} | |
awk -F "$delim" ' | |
BEGIN { end_vale=-10000000 } | |
{ value=$'"$column"'; if (value > end_vale) end_vale = value } | |
END { print end_vale } | |
' | |
} | |
function column-min() { | |
column=$1 | |
delim=${2:-','} | |
awk -F "$delim" ' | |
BEGIN { end_value=10000000 } | |
{ value=$'"$column"'; if (value < end_value) end_value = value } | |
END { print end_value } | |
' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment