Link to home
Start Free TrialLog in
Avatar of Europa MacDonald
Europa MacDonaldFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Counting values in a list

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
Avatar of ozo
ozo
Flag of United States of America image

perl -F, -alne '++$c if $F[0]==101;END{print $c}' master.vim > count.txt
Avatar of Europa MacDonald

ASKER

Thankyou ozo

is that to be run from the command line ?
yes
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.
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 ?
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
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great Solution

thankyou very much