Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

getting line count in cmd.exe

by chuckd (Scribe)
on Sep 15, 2008 at 01:35 UTC ( #711353=perlquestion: print w/ replies, xml ) Need Help??
chuckd has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know how to get a line count in cmd.exe? I can use cygwin's 'wc -l filename', but then I have to have cygwin installed (I'm using a Windows machine). I know I can open the file in Perl and read line by line to the end and take a count but that takes appx. 3 or so lines. I'm trying to do it with as few lines as possible. Thanks.

Comment on getting line count in cmd.exe
Re: getting line count in cmd.exe
by jwkrahn (Monsignor) on Sep 15, 2008 at 01:42 UTC
      Just FTR, appears (testing with 5.8 and w2k against .pl and (ASCII text) .txt files as the targets) that this produces an accurate count on the .pl files, but not so with those named *.txt.

      First suspicion was that some doubled \n instances might be the problem, but further runs aginst .txt files without blank lines disabused me of that: perl -pe"}{$\=$." f:\_wo\(various).txt, consistently undercounted the lines.

      Is it just late on a hot, sticky and perhaps "stupidity-inducing" night, or do others see this too?

        There's no reason why that should be. Why would <> returns something different based on the input's extension.

        >perl -MO=Deparse -pe"}{$\=$." LINE: while (defined($_ = <ARGV>)) { (); } { $\ = $.; } continue { die "-p destination: $!\n" unless print $_; } -e syntax OK

        And I don't see it happening

        >perl -pe"}{$\=$." script.pl 56 >copy script.pl test.txt 1 file(s) copied. >perl -pe"}{$\=$." test.txt 56

        Provide a hexdump of your text file if you want to look into this further.

Re: getting line count in cmd.exe
by poolpi (Hermit) on Sep 15, 2008 at 12:15 UTC

    See Perl Cookbook, chapter 8.2 for more informations

    perl -ne 'END{print $.}' file

    hth,
    PooLpi

    'Ebry haffa hoe hab im tik a bush'. Jamaican proverb

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://711353]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2014-07-29 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (212 votes), past polls