generating frequency table from file

后端 未结 6 2110
暗喜
暗喜 2021-01-31 07:51

Given an input file containing one single number per line, how could I get a count of how many times an item occurred in that file?

cat input.txt
1
2
1
3
1
0
         


        
6条回答
  •  甜味超标
    2021-01-31 08:43

    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
    

提交回复
热议问题