frequency count for file column in bash

后端 未结 3 1022
滥情空心
滥情空心 2021-01-25 18:12

I have a file with 8 columns using | as a delimiter and I want to count the occurence frequency of the words in the 8th column. I tried awk like this



        
3条回答
  •  感情败类
    2021-01-25 18:30

    You can just awk to do this:

    awk -F '|' '{freq[$8]++} END{for (i in freq) print freq[i], i}' file
    

    This awk command uses | as delimiter and uses an array seen with key as $8. When it finds a key $8 increments the frequency (value) by 1. Btw you need to add custom delimiter | in your command and use it like this:

    awk -F '|' '{print $8}' file | sort | uniq -c
    

提交回复
热议问题