0

How do I count lines of files in Windows in the fastest way, without installing any additional software? Basically, only the equivalent of Windows' wc -l filename will do. So no installation of cygwin etc, because I need this to work with installation of other software.

It's not a duplicate of this as that talks about a solution that I can't re-use as it was designed for multiple files..

xiaodai
  • 14,889
  • 18
  • 76
  • 140
  • 4
    I don't know if there is a faster way, but in PowerShell you could do `(Get-Content 'D:\textfile.txt').Count` or make use of .NET `([System.IO.File]::ReadAllLines('D:\textfile.txt')).Count` – Theo Sep 07 '19 at 09:31
  • 2
    In CMD we can combine the builtin `type` command with find.exe: `type filename | find /c /v ""`. Sending the file contents through a pipe cause `find` to omit the summary and just output the line count from the `/c` option. The `/v` option inverts the match on the empty string `""`, so it matches any line. – Eryk Sun Sep 07 '19 at 10:45
  • The accepted answer to the linked question can also be used with a single file. @ErykSun's comment shows a variant that doesn't print the filename. – mklement0 Sep 07 '19 at 21:29

1 Answers1

3

Measure-Object. (There are -word and -character options too.) "type" or "cat" may be an alias for "get-content".

get-content filename | Measure-Object -line

output

Lines Words Characters Property
----- ----- ---------- --------
    3                  
js2010
  • 23,033
  • 6
  • 64
  • 66