Count the distinct list of ids

Hello guys,

I have a file in the following format(each line seperated by TAB):

Filename id
Filename id1
Filename id
Filename1 id7
Filename1 id7
Filename2 id1
Filename2 id1
Filename2 id3
Filename3 id2
Filename3 id4
Filename3 id4
Filename3 id6

I would like to get the count of distinct ids from each file:
Output should like :
Filename 2
Filename1 1
Filename2 2
Filename3 3

Can some please help me?

Your example is confusing for me. Filename 1 in your example output should be Filename 2.

Please try again.

cat <filename> | sort -u | awk '{a[$1]++} END{for (f in a) print f, a[f]}'

this command works for your question.