Solved

counting values in a list 3

Posted on 2013-11-17
9
251 Views
Last Modified: 2013-11-17
I know very little about PERL :(

I have list of millions of rows of data. All data values are separated by a comma

I have to count how many rows contain a specific data value

for example

101,102,143,145,146,149
101,102,143,145,147,148
101,102,143,145,147,149
101,102,143,145,148,149
101,102,143,146,147,148
101,102,143,146,147,149
101,103,143,146,148,149
102,103,143,147,148,149
102,103,144,145,146,147
102,104,144,145,146,148
102,104,144,145,146,149
102,104,144,145,147,148

from that sample list, I have to count how many rows have the value 103 for the second data entry, but only if the value in the first column is 101, so for this list the number of rows with 103 in the second data entry where the first value is 101, would be 1

I have a previous script (attached) from "ozo" which counts the rows with particular values in the first column.

Could you alter this script (as it works very fast) to count the number of rows with 103 in the second column only where the value 101 is in the first column ?

Thankyou very much in advance count1.txt
0
Comment
Question by:MichaelGlancy
  • 5
  • 4
9 Comments
 
LVL 14

Expert Comment

by:jb1dev
ID: 39655001
#!/usr/bin/perl
use strict;
use warnings;
open M,"<master.vim" or die "master.vim $!";
my $c=0;
$c+=/^101,103/ while <M>;
close M;
open C,">count.txt" or die "count.txt $!";
print C "$c\n";
close C;

Open in new window

0
 

Author Comment

by:MichaelGlancy
ID: 39655009
Doesnt work, its posting too high a result in a test list that i have
0
 
LVL 14

Expert Comment

by:jb1dev
ID: 39655012
Can you post the test list that you have?
0
 
LVL 14

Accepted Solution

by:
jb1dev earned 500 total points
ID: 39655015
Oh wait, I guess the numbers can be higher than 3 digits? Need to add a comma after 103.

Try

#!/usr/bin/perl
use strict;
use warnings;
open M,"<master.vim" or die "master.vim $!";
my $c=0;
$c+=/^101,103,/ while <M>;
close M;
open C,">count.txt" or die "count.txt $!";
print C "$c\n";
close C;

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:MichaelGlancy
ID: 39655016
Sorry, it works on the little list I supplied. The test list I have is 5 million entries. I can accept this answer just now and we can work on the next
0
 

Author Closing Comment

by:MichaelGlancy
ID: 39655017
great
0
 

Author Comment

by:MichaelGlancy
ID: 39655035
It works fine on the large list. unfortunately it is picking up


all values with 101,103

and it is including values further down the list with

101,1034 etc so giving me a false result

I will post another question about this

thankyou
0
 
LVL 14

Expert Comment

by:jb1dev
ID: 39655037
0
 

Author Comment

by:MichaelGlancy
ID: 39655044
Ive posted a new question
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now