[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# Counting values in a list 2

Posted on 2013-11-17
Medium Priority
214 Views
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 103 for the second data entry, so for this list the number of rows with 103 in the second data entry would be 3

Could someone help me with a PERL script that I can run as a .pl file and 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 second column
3. write the recorded number of rows to another file (  count103.txt  )
4. close master.vim and count.txt

0
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

LVL 14

Accepted Solution

jb1dev earned 2000 total points
ID: 39654944
``````#!/usr/bin/perl

open FILE, "<master.vim";
my \$count = 0;

while(<FILE>) {
my @columns = split(',');
if(\$columns[1] eq '103') {
\$count++;
}
}
close FILE;

open OUT, ">count.txt";
print OUT "\$count\n";
close OUT;
``````
0

Author Closing Comment

ID: 39654961
great thanks
0

## Featured Post

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Progress
###### Suggested Courses
Course of the Month13 days, 9 hours left to enroll