↑ ↓ select, Enter open, Esc close

Calculate the average, minimum and maximum of a column

Adjust the values, the command updates live
user@server
awk -v c=2 'NR == 1 {min = max = $c} {s += $c; if ($c < min) min = $c; if ($c > max) max = $c} END {if (NR) printf "n=%d avg=%.2f min=%s max=%s\n", NR, s/NR, min, max}' measurements.txt

Reads the given column of each line, keeps track of the smallest and largest value and finally prints the count, the average with two decimal places, the minimum and the maximum. Suitable for measurement series, load times from logs or size lists. The file should contain data lines only.

Note: A header line skews the result, cut it off beforehand with tail -n +2 datei | awk ....

Also searched as

  • awk average of a column
  • calculate average response time command line
  • find min and max value in column linux

Related one-liners

All in Text processing

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.