Statistics
Find minimum and maximum of a column
cat <<'EOF' > /tmp/demo.txt
23.4
87.1
12.6
45.9
91.3
34.7
68.2
EOF
awk 'NR==1 || $1<min {min=$1} NR==1 || $1>max {max=$1} END{print "Min:", min, "Max:", max}' /tmp/demo.txt
Count, sum, average, min, max in one pass
cat <<'EOF' > /tmp/demo.txt
3.2
7.8
1.5
9.4
4.6
6.1
8.3
2.7
5.9
EOF
awk 'NR==1{min=max=$1} {sum+=$1; if($1<min) min=$1; if($1>max) max=$1} END{printf "n=%d sum=%.2f avg=%.2f min=%.2f max=%.2f\n", NR, sum, sum/NR, min, max}' /tmp/demo.txt
Standard deviation (population)
cat <<'EOF' > /tmp/demo.txt
42
38
55
61
47
53
44
49
56
50
EOF
awk '{sum+=$1; sumsq+=$1*$1} END{printf "stddev=%.4f\n", sqrt(sumsq/NR-(sum/NR)^2)}' /tmp/demo.txt
Percentile calculation — sort externally, pick position
cat <<'EOF' > /tmp/demo.txt
12
45
23
89
67
34
91
56
78
15
43
88
31
72
64
19
53
82
37
61
EOF
sort -n /tmp/demo.txt | awk '{a[NR]=$1} END{p95=a[int(NR*0.95)]; p99=a[int(NR*0.99)]; printf "p95=%.2f p99=%.2f\n", p95, p99}'
Histogram — bucket values into ranges
cat <<'EOF' > /tmp/demo.txt
3
15
22
7
31
48
12
27
35
41
18
9
24
37
44
6
29
33
11
46
EOF
awk '{bucket=int($1/10)*10; hist[bucket]++} END{for(b in hist) printf "%4d-%4d: %s (%d)\n", b, b+9, sprintf("%*s",hist[b],""), hist[b]}' /tmp/demo.txt | sort -n
Response time statistics from access log (field $NF = response time ms)
cat <<'EOF' > /tmp/access.log
10.50.1.10 - - [11/Apr/2026:08:15:01 +0000] "GET /api/health HTTP/1.1" 200 512 "-" "curl/8.7" 23
10.50.1.20 - - [11/Apr/2026:08:15:03 +0000] "POST /api/auth HTTP/1.1" 200 2048 "-" "python/3.12" 145
10.50.1.10 - - [11/Apr/2026:08:15:05 +0000] "GET /api/users HTTP/1.1" 200 8192 "-" "curl/8.7" 67
10.50.1.30 - - [11/Apr/2026:08:15:08 +0000] "GET /static/logo.png HTTP/1.1" 200 34816 "-" "Mozilla/5.0" 312
10.50.1.10 - - [11/Apr/2026:08:15:10 +0000] "DELETE /api/sessions HTTP/1.1" 204 0 "-" "curl/8.7" 18
10.50.1.20 - - [11/Apr/2026:08:15:12 +0000] "GET /api/status HTTP/1.1" 200 1024 "-" "python/3.12" 42
EOF
awk '{sum+=$NF; sumsq+=$NF*$NF; if(NR==1||$NF<min) min=$NF; if($NF>max) max=$NF} END{printf "avg=%.1fms min=%dms max=%dms stddev=%.1fms n=%d\n", sum/NR, min, max, sqrt(sumsq/NR-(sum/NR)^2), NR}' /tmp/access.log