在bash中的列中获取唯一值的计数 [英] Getting the count of unique values in a column in bash

查看:154
本文介绍了在bash中的列中获取唯一值的计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个列的制表符分隔文件。我想计算文件夹中所有文件的列中不同值的出现频率,并按计数的降序排列(最高计数首先)。

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 decreasing order of count (highest count first). How would I accomplish this in a Linux command line environment?

它可以使用任何常用的命令行语言,如awk,perl,python等。

It can use any common command line language like awk, perl, python etc.

推荐答案

要查看第二列的频率计数(例如):

To see a frequency count for column two (for example):

awk -F '\t' '{print $2}' * | sort | uniq -c | sort -nr

fileA.txt

fileA.txt

z    z    a
a    b    c
w    d    e

fileB.txt

fileB.txt

t    r    e
z    d    a
a    g    c

fileC.txt

fileC.txt

z    r    a
v    d    c
a    m    c

结果:

  3 d
  2 r
  1 z
  1 m
  1 g
  1 b

这篇关于在bash中的列中获取唯一值的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆