Skip to content

Instantly share code, notes, and snippets.

@jazzdev
Forked from jamerfort/avg.awk
Last active May 29, 2018 10:21
Show Gist options
  • Save jazzdev/a8a2e81a67d7bd398a04a876dd17e880 to your computer and use it in GitHub Desktop.
Save jazzdev/a8a2e81a67d7bd398a04a876dd17e880 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+0 > MAX ) { MAX=$1+0 } }
END { print MAX }
#!/usr/bin/awk -f
{ if( MIN == "" || $1+0 < MIN ) { MIN=$1+0 } }
END { print MIN }
#!/usr/bin/awk -f
BEGIN { TOTAL=0 }
{ TOTAL = TOTAL + $1 }
END { print TOTAL }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment