finding out how many times something comes up

Hi,

I have a file that looks something like this:

YPA124  NV
YPA124  NV
YPA124  V
YAR198  V
YAR198  V
YOB911  V
YOB911  V
YOB911  NV
YOB911  NA

So what i want to do is find out how many times each name on column 1 is represented by indicators on column 2.

So the output would look like this (column 1 would be the name, 2 would be the indicator and 3 would be how many times that indicator comes up per name):

YPA124  NV  2
YPA124  V    1
YAR198  V    2
YOB911  V    2
YOB911  NV  1
YOB911  NA   1

obviously I do not know how to do this so any help would be gladly appreciated.

thanks

If the file is not sorted, then sort explicitly

uniq -dc file

Hi,

uniq -c writes the number of repetations at the beginning of the line , with a trick u can change it:

uniq -c FILE.txt | awk '{printf "%s %-4s %-s\n",$2,$3,$1}'

output:

YPA124 NV   2   
YPA124 V    1   
YAR198 V    2   
YOB911 V    2   
YOB911 NV   1   
YOB911 NA   1 
awk ' { arr[$0]++} END{for (i in arr){print arr, i }} ' file > newfile
while(<DATA>){
	chomp;
	my @tmp = split;
	$hash{$tmp[0]}->{$tmp[1]}++;
	$hash{$tmp[0]}->{_SEQ_}=$.
}
foreach my $key(sort {$hash{$a}->{_SEQ_} <=> $hash{$b}->{_SEQ_}} keys %hash){
	my %tmp = %{$hash{$key}};
	foreach my $k( grep {$_ ne "_SEQ_"}  keys %tmp){
		print $key," ",$k," ",$tmp{$k},"\n";
	}
}
__DATA__
YPA124  NV
YPA124  NV
YPA124  V
YAR198  V
YAR198  V
YOB911  V
YOB911  V
YOB911  NV
YOB911  NA