I have a list, with data on each row separated by a comma. I have several columns of data.
1,2,3,4,5,6,avg1,3.50,60000,1,1,1,1,1,avg2,1.0
x,x,x,x,x,x,text,1.1,60000,x,x,x,x,x,text,x
x,x,x,x,x,x,text,1.1,60000,x,x,x,x,x,text,x
x,x,x,x,x,x,text,1.1,60000,x,x,x,x,x,text,x
x,x,x,x,x,x,text,1.1,03030,x,x,x,x,x,text,x
x,x,x,x,x,x,text,1.1,03030,x,x,x,x,x,text,x
x,x,x,x,x,x,text,1.1,02220,x,x,x,x,x,text,x
It is the data in the 10th column that I have to count. With the result for the above sample list being
60000 3
03030 2
02220 1
The thing is, it is not a number, I have to look at it as text, and count the variations as I find them.
I tried using this code
#!/usr/bin/perl
use strict;
use warnings;
open M,"<master_sorted_002_reduced.vim" or die "master_sorted_002_reduced.vim $!";
my $c=0;
$c+= /[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,(\d+)/ while <M>;
close M;
open C,">count4.txt" or die "count4.txt $!";
print C "$_ $c\n";
close C;
But it only seems to count the number of lines ?
Could you please help me with code which will count the rows, and report the variable and the number of each variable that it finds ? without treating it like a number ?
Open in new window