command line utility to print statistics of numbers in linux

后端 未结 16 1622
無奈伤痛
無奈伤痛 2020-11-30 18:46

I often find myself with a file that has one number per line. I end up importing it in excel to view things like median, standard deviation and so forth.

Is there a

16条回答
  •  孤独总比滥情好
    2020-11-30 19:18

    Using xsv:

    $ echo '3 1 4 1 5 9 2 6 5 3 5 9' |tr ' ' '\n' > numbers-one-per-line.csv
    
    $ xsv stats -n < numbers-one-per-line.csv 
    field,type,sum,min,max,min_length,max_length,mean,stddev
    0,Integer,53,1,9,1,1,4.416666666666667,2.5644470922381863
    
    # mode/median/cardinality not shown by default since it requires storing full file in memory:
    $ xsv stats -n --everything < numbers-one-per-line.csv | xsv table
    field  type     sum  min  max  min_length  max_length  mean               stddev              median  mode  cardinality
    0      Integer  53   1    9    1           1           4.416666666666667  2.5644470922381863  4.5     5     7
    

提交回复
热议问题