Skip to content

Instantly share code, notes, and snippets.

@jamerfort
Created November 28, 2012 21:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jamerfort/4164638 to your computer and use it in GitHub Desktop.
Save jamerfort/4164638 to your computer and use it in GitHub Desktop.
Awk scripts for total/average/max/min. All numbers come in on STDIN
#!/usr/bin/awk -f
BEGIN { TOTAL=0 }
{ TOTAL = TOTAL + $1 }
END { print TOTAL/NR }
#!/usr/bin/awk -f
{ if( MAX == "" || $1 > MAX ) { MAX=$1 } }
END { print MAX }
#!/usr/bin/awk -f
{ if( MIN == "" || $1 < MIN ) { MIN=$1 } }
END { print MIN }
#!/usr/bin/awk -f
BEGIN { TOTAL=0 }
{ TOTAL = TOTAL + $1 }
END { print TOTAL }
@jazzdev
Copy link

jazzdev commented May 8, 2018

The max and min give the wrong value. Replace $1 with $1+0
in those scripts to fix. I'd do a PR, if Github supported PRs on Gists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment