Hey guys so i got this dummy data: 

```
115,IROM,1
125,FOLCOM,1
135,SE,1
111,ATLUZ,1
121,ATLUZ,2
121,ATLUZ,2
142,ATLUZ,2
142,ATLUZ,2
144,BLIZZARC,1
166,STEAD,3
166,STEAD,3
166,STEAD,3
168,BANDOI,1
179,FOX,1
199,C4,2
199,C4,2

```

Desired output:

```
IROM,1
FOLCOM,1
SE,1
ATLUZ,3
BLIZZARC,1
STEAD,1
BANDOI,1
FOX,1
C4,1

```

which comes from counting the distinct game id (the 115,125,etc). so for example the

```
111,ATLUZ,1
121,ATLUZ,2
121,ATLUZ,2
142,ATLUZ,2
142,ATLUZ,2

```

Will be

```
ATLUZ,3 

```

Since it have 3 distinct game id

I tried using 

```
cut -d',' -f 2 game.csv|uniq -c

```

Where i got the following output

```
  1 IROM
  1 FOLCOM
  1 SE
  5 ATLUZ
  1 BLIZZARC COMP
  3 STEAD
  1 BANDOI
  1 FOX
  2 C4

```

How do i fix this ? using bash ?
['https://Stackoverflow.com/questions/51943181', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3646742/']
Using [GNU `datamash`](https://www.gnu.org/software/datamash/manual/datamash.html):

```
datamash -t, --sort --group 2 countunique 1 < input

```

Using [`awk`](https://www.gnu.org/software/gawk/manual/gawk.html):

```
awk -F, '!a[$1,$2]++{b[$2]++}END{for(i in b)print i FS b[i]}' input

```

Using [`sort`](https://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html), [`cut`](https://www.gnu.org/software/coreutils/manual/html_node/cut-invocation.html), [`uniq`](https://www.gnu.org/software/coreutils/manual/html_node/uniq-invocation.html):

```
sort -u -t, -k2,2 -k1,1 input | cut -d, -f2 | uniq -c

```

---

**Test run:**

```
$ cat input
111,ATLUZ,1
121,ATLUZ,1
121,ATLUZ,2
142,ATLUZ,2
115,IROM,1
142,ATLUZ,2
$ datamash -t, --sort --group 2 countunique 1 < input
ATLUZ,3    
IROM,1

```

As you can see, `121,ATLUZ,1` and `121,ATLUZ,2` are correctly considered to be just one `game ID`.
Less elegant, but you may use awk as well. If it is not granted that the same ID+NAME combos will always come consecutively, you have to count each by reading the whole file before output:

```
awk -F, '{c[$1,$2]+=1}END{for (ck in c){split(ck,ca,SUBSEP); print ca[2];g[ca[2]]+=1}for(gk in g){print gk,g[gk]}}' game.csv

```

This will count first every [COL1,COL2] pairs then for each COL2 it counts how many distinct [COL1,COL2] pairs are nonzero.