Getting the count of unique values in a column in bash

后端 未结 5 984
一整个雨季
一整个雨季 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:24

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

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

    fileA.txt

    z    z    a
    a    b    c
    w    d    e
    

    fileB.txt

    t    r    e
    z    d    a
    a    g    c
    

    fileC.txt

    z    r    a
    v    d    c
    a    m    c
    

    Result:

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

提交回复
热议问题