Solved

counting rows in a list 4

Posted on 2013-11-17
2
237 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 "jb1dev + ozo" which counts the rows with particular values in the first and second column.

The problem that I have that this script is that it also includes any values in the second column that have 103 within them, for example, 1034, 1035 and so giving me an artificially high count.

I need this script to count only those rows with specifically 101, and 103 with no other combinations

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 ? and specifically ONLY those values I ask for ?

Thankyou very much in advance
count3a.txt
0
Comment
Question by:MichaelGlancy
2 Comments
 
LVL 14

Accepted Solution

by:
jb1dev earned 500 total points
ID: 39655060
#!/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 Closing Comment

by:MichaelGlancy
ID: 39655066
works great thankyou
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 169
Android development question 2 51
Eclipse Java import and method not resolved 4 43
Perl script to process a .csv file 18 44
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

790 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