Skip to content

Latest commit

 

History

History
71 lines (68 loc) · 1.21 KB

File metadata and controls

71 lines (68 loc) · 1.21 KB

Generate a histogram using awk

awk '{
  # Set group range
  x=$1 - $1 % 200
  arr[x] += 1
}
END {
  for (key in arr) {
    $2=sprintf("%-*s", arr[key], "");
    # Limit width
    if (arr[key] > 60) $2=substr($2, 0, 60) "..."
    gsub(" ", "=", $2);
    printf("%s\t%s\t%s\n", key, arr[key], $2)
  }
}' input_data.txt | sort -n

Sample input:

3
7
26
46
6
9
4
3
4
5
3
14
10
2761
5
248
3
7
25
4
4
...(etc)

Sample output:

0	98250	============================================================...
200	1014	============================================================...
400	315	============================================================...
600	124	============================================================...
800	95	============================================================...
1000	72	============================================================...
1200	56	========================================================
1400	46	==============================================
1600	27	===========================
1800	27	===========================
2000	9	=========
2200	20	====================
2400	14	==============
2600	5	=====
2800	3	===
3000	5	=====
3200	1	=
3400	1	=
3600	1	=
3800	1	=
4600	1	=
5200	1	=
7200	1	=