AWK计数频率 [英] Awk count frequency
本文介绍了AWK计数频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我要计算在awk中某列的数据量。结果
一个例子是数据结果 2 5 8结果
结果
1 3 7结果
8 5 9
我想算5的频率在第二柱。这就是我想,没有工作。
{
总= 0;
对于(i = 1; I< = NF;我++)
{
如果(ⅰ== 2)
{如果($ I == 5){总++;}}
的printf(%S,总数);}
}
解决方案
如何以下内容:
的awk'{如果($ 2 == 5)计数++} END {打印计数}
Hey i want to count the amount of data in a certain column in awk.
an example dataset is
2 5 8
1 3 7
8 5 9
and I want to count the frequency of the 5 in the second colum. This is what i tried that didn't work
{
total = 0;
for(i=1;i<=NF;i++)
{
if(i==2)
{if($i==5) {total++;}
}
printf("%s ", total);
}
}
解决方案
How about the following:
awk '{ if ($2==5) count++ } END { print count }'
这篇关于AWK计数频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文