Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

counting rows in a list 4

Posted on 2013-11-17
2
Medium Priority
?
245 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:Europa MacDonald
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
jb1dev earned 2000 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:Europa MacDonald
ID: 39655066
works great thankyou
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

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.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Starting up a Project

670 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