On May 4, Susan Richter said:

>Can someone tell me what command I can use to go to machines and count the 
>lines on a certain file?  I have log files for every machines (20 all 
>together).  Each log file has lines that would equate to the files that it 
>found.  I need to know how many files are found on all the machines.  I am 
>using Perl 5 on NT.

perldoc -q lines

=head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq5.pod

=head2 How do I count the number of lines in a file?

One fairly efficient way is to count newlines in the file. The
following program uses a feature of tr///, as documented in L<perlop>.
If your text file doesn't end with a newline, then it's not really a
proper text file, so this may report one fewer line than you expect.

    $lines = 0;
    open(FILE, $filename) or die "Can't open `$filename': $!";
    while (sysread FILE, $buffer, 4096) {
        $lines += ($buffer =~ tr/\n//);
    }
    close FILE;

This assumes no funny games with newline translations.


-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734

Reply via email to