Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Get counts from List

$
0
0
This is very easy , but I`m struggling .. please help modify my script,

I want to count the number of h and n , from the second column group by the first. The second column is binary, can only have h and n.


Code:

a        h
a        h
a        n
a        n
a        h
b        h
b        h
b        h
b        h
b        h
c        n
c        h
c        h
c        h
c        h

Desired output

Code:

        h        n
a        3        2
b        5        0
c        4        1


My try

Code:

awk  '{A[$1]+=$2}END{for (i in A) print i,A[i]}' file

Viewing all articles
Browse latest Browse all 16232

Trending Articles