根据column1打印column2的数量(print the number of column2 based on column1)
我有一个文件如下所示。 我想打印每个科目的学生人数(重复的名字不想计算)。
alvy science eby maths alvy science bitty science monika maths eby maths johny social如何使用awk获得以下输出?
`no:of students in` science- 2 no:of students in maths - 2 no:of students in social - 1I have a file as shown below. I would like to print the number of students in each subject(duplicated names don't want to count).
alvy science eby maths alvy science bitty science monika maths eby maths johny socialHow do I get the following output with awk?
`no:of students in` science- 2 no:of students in maths - 2 no:of students in social - 1最满意答案
以下代码应该适合您:
awk '!s[$1, $2]++ {arr[$2]++} END {for (i in arr) print "no:of students in", i, "-", arr[i]}'Here is the code that should work for you:
awk '!s[$1, $2]++ {arr[$2]++} END {for (i in arr) print "no:of students in", i, "-", arr[i]}'更多推荐
发布评论