generating frequency table from file generating frequency table from file shell shell

generating frequency table from file


You mean you want a count of how many times an item appears in the input file? First sort it (using -n if the input is always numbers as in your example) then count the unique results.

sort -n input.txt | uniq -c


Another option:

awk '{n[$1]++} END {for (i in n) print i,n[i]}' input.txt | sort -n > output.txt


Using maphimbu from the Debian stda package:

# use 'jot' to generate 100 random numbers between 1 and 5# and 'maphimbu' to print sorted "histogram":jot -r 100 1 5 | maphimbu -s 1

Output:

             1                20             2                21             3                20             4                21             5                18

maphimbu also works with floating point:

jot -r 100.0 10 15 | numprocess /%10/ | maphimbu -s 1

Output:

             1                21           1.1                17           1.2                14           1.3                18           1.4                11           1.5                19