bash: getting percentage from a frequency table

前端 未结 2 1377
粉色の甜心
粉色の甜心 2021-02-20 03:34

i had made a small bash script in order to get the frequency of items in a certain column of a file.

The output would be sth like this

A     30
B     25
         


        
2条回答
  •  醉梦人生
    2021-02-20 03:52

    Try this (with the sort moved to the end:

    cut -f $1 $2| sort | uniq -c  | awk '{array[$2]=$1; sum+=$1} END { for (i in array) printf "%-20s %-15d %6.2f%%\n", i, array[i], array[i]/sum*100}' | sort -r -k2,2 -n
    

提交回复
热议问题