Europa MacDonald
asked on
Counting rows in a list 7
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,6000 0,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_redu ced.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 ?
1,2,3,4,5,6,avg1,3.50,6000
x,x,x,x,x,x,text,1.1,60000
x,x,x,x,x,x,text,1.1,60000
x,x,x,x,x,x,text,1.1,60000
x,x,x,x,x,x,text,1.1,03030
x,x,x,x,x,x,text,1.1,03030
x,x,x,x,x,x,text,1.1,02220
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_redu
my $c=0;
$c+= /[^,]*,[^,]*,[^,]*,[^,]*,[
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 ?
ASKER
thanks, Ive tried it, and I get a temporary window open and close.
I dont know a lot about PERL or programming. How do I get the results to print to a text file ?
I dont know a lot about PERL or programming. How do I get the results to print to a text file ?
Run the script from the command line.
Given your sample data, the column you say you need is the 9th, not the 10th.
Here's the results I get after adjusting the column index on the array slice.
c:\test>Michael.pl
Given your sample data, the column you say you need is the 9th, not the 10th.
Here's the results I get after adjusting the column index on the array slice.
c:\test>Michael.pl
$VAR1 = {
'60000' => 3,
'03030' => 2,
'02220' => 1
};
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thankyou very much works great :)
Open in new window