Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Counting values in a list

Posted on 2013-11-17
8
Medium Priority
?
221 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
101,103,143,147,148,149
101,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 101 for the first data entry, so for this list the number of rows with 101 in the first data entry would be 9

Could someone help me with a PERL script that will

1. open the file  (filename:  master.vim )
2. Count through all the rows and record the number of rows with the value at that data point - in the first column
3. write the recorded number of rows to another file ( count.txt )
4. close master.vim and count.txt

Thankyou very much in advance
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
  • 4
  • 4
8 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 39654634
perl -F, -alne '++$c if $F[0]==101;END{print $c}' master.vim > count.txt
0
 

Author Comment

by:Europa MacDonald
ID: 39654637
Thankyou ozo

is that to be run from the command line ?
0
 
LVL 84

Expert Comment

by:ozo
ID: 39654729
yes
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Europa MacDonald
ID: 39654753
C:\Documents and Settings\Michael>perl -F, -alne '++$c if $
F[0]==101;END{print $c}' master.vim > count.txt

Can't find string terminator "'" anywhere before EOF at -e line 1.
0
 

Author Comment

by:Europa MacDonald
ID: 39654756
I have no idea what I am doing with PERL

Would it be possible for you to give me this information such that I can put it into a .pl file, that I can run in the same directory as the master file ?
0
 
LVL 84

Expert Comment

by:ozo
ID: 39654764
In msdos, you would quote the command line with " instead of '
perl -F, -alne "++$c if $F[0]==101;END{print $c}" master.vim > count.txt
0
 
LVL 84

Accepted Solution

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

Author Closing Comment

by:Europa MacDonald
ID: 39654933
Great Solution

thankyou very much
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
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…
Suggested Courses

636 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