[英]awk print number of row only in uniq column
I have data set like this: 我有这样的数据集:
1 A
1 B
1 C
2 A
2 B
2 C
3 B
3 C
And I have a script which calculates me: 我有一个脚本来计算我:
Number of occurrences in searching string 搜索字符串中的出现次数
Number of rows 行数
awk -v search="A" \\ 'BEGIN{count=0} $2 == search {count++} END{print count "\\n" NR}' input
That works perfectly fine. 那很好。
I would like to add to my awk
one liner number of unique lines from the first column. 我想在第一列中添加awk
唯一行的衬里数。
So the output should be separated by \\n : 因此,输出应以\\ n分隔:
2
8
3
I can do this in separate awk
code, but I am not able to integrate it to my original awk
code. 我可以在单独的awk
代码中执行此操作,但是无法将其集成到我的原始awk
代码中。
awk '{a[$1]++}END{for(i in a){print i}}' input | wc -l
Any idea how to integrate it in one awk
solution without piping ? 知道如何在不使用管道的情况下将其集成到一个awk
解决方案中吗?
Looks like you want this: 看起来您想要这样:
awk -v search="A" '{a[$1]++}
$2 == search {count++}
END{OFS="\n";print count+0, NR, length(a)}' file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.