assigning counter to same keys in a file

Hi,
I've a data file with similar keys coming in. I want to assign an incremental counter to those records and attach to a file

for example

File
10001 ABCD
10002 PQRS
10001 ABCD
10003 QWER
10001 ABCD
10002 PQRS
10004 POIU

output as
10001 ABCD 1
10002 PQRS 1
10001 ABCD 2
10003 QWER 1
10001 ABCD 3
10002 PQRS 2
10004 POIU 1

any help guys....
can we do it with awk?

Thanks

Use nawk or /usr/xpg4/bin/awk on Solaris:

awk '$(NF+1)=++c[$0]' filename

If you want to preserve consecutive default FS characters:

awk '{print$0,++c[$0]}' filename
awk '{a[$1]++}$0=$0 FS a[$1]' file

Thanks, exactly what i was looking for...
could you please explain?