Europa MacDonald
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
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
perl -F, -alne '++$c if $F[0]==101;END{print $c}' master.vim > count.txt
ASKER
Thankyou ozo
is that to be run from the command line ?
is that to be run from the command line ?
yes
ASKER
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.
F[0]==101;END{print $c}' master.vim > count.txt
Can't find string terminator "'" anywhere before EOF at -e line 1.
ASKER
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 ?
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
perl -F, -alne "++$c if $F[0]==101;END{print $c}" master.vim > count.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great Solution
thankyou very much
thankyou very much