Getting the count of unique values in a column in bash

后端 未结 5 894
一整个雨季
一整个雨季 2021-01-30 08:14

I have tab delimited files with several columns. I want to count the frequency of occurrence of the different values in a column for all the files in a folder and sort them in d

5条回答
  •  臣服心动
    2021-01-30 08:34

    Ruby(1.9+)

    #!/usr/bin/env ruby
    Dir["*"].each do |file|
        h=Hash.new(0)
        open(file).each do |row|
            row.chomp.split("\t").each do |w|
                h[ w ] += 1
            end
        end
        h.sort{|a,b| b[1]<=>a[1] }.each{|x,y| print "#{x}:#{y}\n" }
    end
    

提交回复
热议问题