38

A quick search gives me tawbaware wc, but it does not accept stdout as input stream, meaning I can not use pipe within a DOS session.

Note:

I can not install cygwin or use powershell (which would have allowed a '|foreach-object {(get-content $_).count}')

unxutils and and gnuwin32 Packages might have this feature...

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250

10 Answers10

33

Even easier, find /c. ex:

netstat -an | find /c "ESTABLISHED"

find /c: Displays only the count of lines containing the string.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
jeff drake
  • 331
  • 3
  • 2
31

You can use the original "wc", built for windows: it is part of the coreutils package. Get the most recent coreutils exe.

cweiske
  • 30,033
  • 14
  • 133
  • 194
florin
  • 13,986
  • 6
  • 46
  • 47
  • downloading it now, but a quick (too quick) survey of the page http://gnuwin32.sourceforge.net/packages.html did not let me believe wc was included in that distribution... – VonC Oct 29 '08 at 15:36
  • 4
    installed and used with a |. It works (provided libiconv2.dll and libintl3.dll are there as well). Thank you! – VonC Oct 29 '08 at 15:43
10

For unix tools on windows your options are:

msys - similair to unixtools, originally just a few build tools needed to go with mingw (native version of gcc), now has almost all of the cygwin tools

cygwin - just about everythign for unix, complex install and requires a dll to provide unix api. Can be problems mixing tools built with different versions of cygwin.dll

Unixtools - not all the tools provided by cygwin but compiled natively

ch - pretty much all the unix tools, compiled natively. And a shell which includes a 'c' interpreter. The standard version is free (beer) but not open source.

uwin - free from ATT, includes the korn shell if you like that sort of thing.

mks a Commercial port of unix tools. Rather expensive given the free versions available.

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
  • Thank you for that list. I will certainly refer to it for any future similar request. +1 – VonC Oct 29 '08 at 15:50
5

Try:

find /c /v "~any string that will never occur~"

This command gives a count of all lines that DO NOT contain the search string. Testing it, I see a problem that it doesn't seem to count blank lines at the end of a file.

Víctor López
  • 819
  • 1
  • 7
  • 19
Dan S.
  • 81
  • 1
  • 2
3

Well, I'm sorry to disagree, but unxutils do have a wc.exe

Give it a try!

Cheers,

Vinzz
  • 3,968
  • 6
  • 36
  • 51
3

My unxutils pack has word count:

C:\Java\vssWorkspace\java\portlets_core>wc -l C:\Users\malp\AppData\Local\Temp__portlets41366.html 79717 C:\Users\malp\AppData\Local\Temp__portlets41366.html

Besides, the unxutils page indicates wc.exe is available. Are you looking for something that wc.exe does not handle?

Miguel Ping
  • 18,082
  • 23
  • 88
  • 136
2

Here are two other (pure Windows CMD) ways to count lines in a git log:

set n=0
for /f %a in ('git log --oneline') do set /a n=n+1

Or:

git log --online | find /v /c ""

The advantage of the first one is that you end up with the value in an environment variable you can do stuff with. But it might perform slow with huge files.

  • Yes, interesting it is, but not really an answer to the original question. - Should probably be a comment to the answer by @jeffdrake. The rep-restriction on commenting can be a pain in the ... - thing that feels pain... ;) – I'm with Monica Sep 26 '12 at 12:27
0

I found this thread and was charmed by the innovative solutions for emulating wc using just the tools that Windows has built in. This stimulated an answer to my need for a character count so that I might prevail in my battle with a web form field's max character warning.

If you want wc -c which gives a byte count you can use DEBUG, a DOS utility (which isn't listed by the HELP command) in Windows. Character count should equal byte count minus the line count times the size of a newline, which is one newline character for Unix ('\n') or two characters, carriage return + linefeed ('\cr' and '\lf' or '\0Dh' '0Ah' for a DOS plain text file.

Char Count = Byte Count - (Line Count * sizeof("\n"))

To do this open a command line window (Start->Run->Open: "cmd"), run debug on the plain text file and examine the CX register which contains the length of the file loaded:

Debug [pathname] -rcx CX [filelength in hex] : -q

Then run find on the file:

find /v /c "notlikelystring" ---------- [pathname]: [line count]

And apply the formula.

0

There is also WinXs 4.2, it's shareware, so you could see if it'll do what you need it to.

Could you install a script language for this? It might be overkill, but if it gets the job done with a minimum of fuss...

  • interesting, but not free. As for the scripting language, the startup time is too slow compared to a single wc.exe (we have 5-6 years old PC... ;-) ) – VonC Oct 29 '08 at 15:46
-1

getgnuwin32 facilitates downloading and installing of gnuwin32 (which certainly has wc utility).

jfs
  • 399,953
  • 195
  • 994
  • 1,670