Skip to content

Instantly share code, notes, and snippets.

@darencard
Last active November 25, 2022 01:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darencard/785015b8e2cb3c5fbc7d to your computer and use it in GitHub Desktop.
Save darencard/785015b8e2cb3c5fbc7d to your computer and use it in GitHub Desktop.
Calculating the mean, minimum, and maximum of a column using Awk (vary $3 to reflect desired column of data)
cat <input.txt> | awk '{if(min==""){min=max=$3}; if($3>max) {max=$3}; if($3< min) {min=$3}; total+=$3; count+=1} END {print "mean =", total/count, "\nminimum =", min, "\nmaximum =", max}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment