Solved

counting rows in a list 4

Posted on 2013-11-17
2
234 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
Comment Utility
#!/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
Comment Utility
works great thankyou
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

743 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

8 Experts available now in Live!

Get 1:1 Help Now