Solved

Counting values in a list

Posted on 2013-11-17
8
216 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:MichaelGlancy
[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:MichaelGlancy
ID: 39654637
Thankyou ozo

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

Expert Comment

by:ozo
ID: 39654729
yes
0
Technology Partners: 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!

 

Author Comment

by:MichaelGlancy
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:MichaelGlancy
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 500 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:MichaelGlancy
ID: 39654933
Great Solution

thankyou very much
0

Featured Post

Technology Partners: 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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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.
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 …

726 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