Count Column and Print at last

HI Guys,

Count base on column A

Input:-

U00393 6 000100000
U00393 7 000100001
U00393 8 000100002
U00393 9 000100003
U00393 10 000100004
U00393 11 000100005
U00928 6 000100000
U00928 7 000100001
U00964 6 000100000
U00964 7 000100001
U00964 8 000100002
U00972 6 000100000
U00972 7 000100001
U00984 6 000100000
U00984 7 000100001
U00984 8 000100002

Output:-

U00393 6 000100000 1
U00393 7 000100001 2
U00393 8 000100002 3
U00393 9 000100003 4
U00393 10 000100004 5
U00393 11 000100005 6
U00928 6 000100000 1
U00928 7 000100001 2
U00964 6 000100000 1
U00964 7 000100001 2
U00964 8 000100002 3
U00972 6 000100000 1
U00972 7 000100001 2
U00984 6 000100000 1
U00984 7 000100001 2
U00984 8 000100002 3

Try:

awk '
$1 != prev {c=1; prev=$1}
{       print $0,c++}
' Input

If you are using a Solaris/SunOS system use /usr/xpg4/bin/awk or nawk instead of awk .

awk '{A[$1]++;print $0,A[$1]}' file

OR

awk '{A[$1]++;$0=$0 FS A[$1]}1' file
$ cat temp.x
U00393 6 000100000
U00393 7 000100001
U00393 8 000100002
U00393 9 000100003
U00393 10 000100004
U00393 11 000100005
U00928 6 000100000
U00928 7 000100001
U00964 6 000100000
U00964 7 000100001
U00964 8 000100002
U00972 6 000100000
U00972 7 000100001
U00984 6 000100000
U00984 7 000100001
U00984 8 000100002
$ cat temp.sh
A_PREV=xxxxxx N=1
while read A B C; do
  if [ "$A" != "$A_PREV" ]; then
    N=1;
  fi
  echo $A $B $C $N
  N=`expr $N + 1`
  A_PREV=$A
done < temp.x
$ ./temp.sh
U00393 6 000100000 1
U00393 7 000100001 2
U00393 8 000100002 3
U00393 9 000100003 4
U00393 10 000100004 5
U00393 11 000100005 6
U00928 6 000100000 1
U00928 7 000100001 2
U00964 6 000100000 1
U00964 7 000100001 2
U00964 8 000100002 3
U00972 6 000100000 1
U00972 7 000100001 2
U00984 6 000100000 1
U00984 7 000100001 2
U00984 8 000100002 3