Do you know a similar program for wc (unix word count command) on Windows? [closed]
Asked Answered
G

10

40

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...

Gramarye answered 29/10, 2008 at 15:26 Comment(1)
wc is in coreutils (part of the gnuwin32 distribution you linked to).Loewe
L
31

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

Loewe answered 29/10, 2008 at 15:33 Comment(2)
downloading it now, but a quick (too quick) survey of the page gnuwin32.sourceforge.net/packages.html did not let me believe wc was included in that distribution...Gramarye
installed and used with a |. It works (provided libiconv2.dll and libintl3.dll are there as well). Thank you!Gramarye
F
33

Even easier, find /c. ex:

netstat -an | find /c "ESTABLISHED"

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

Furnishing answered 27/1, 2011 at 18:37 Comment(1)
Interesting use of find there. +1Gramarye
L
31

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

Loewe answered 29/10, 2008 at 15:33 Comment(2)
downloading it now, but a quick (too quick) survey of the page gnuwin32.sourceforge.net/packages.html did not let me believe wc was included in that distribution...Gramarye
installed and used with a |. It works (provided libiconv2.dll and libintl3.dll are there as well). Thank you!Gramarye
G
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.

Gobbler answered 29/10, 2008 at 15:45 Comment(1)
Thank you for that list. I will certainly refer to it for any future similar request. +1Gramarye
S
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.

Sisterly answered 4/12, 2010 at 16:18 Comment(0)
T
3

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

Give it a try!

Cheers,

Trickish answered 29/10, 2008 at 15:34 Comment(1)
you are right, my initial search was too quick. +1 but I will go with coreutilsGramarye
P
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?

Phenica answered 29/10, 2008 at 15:34 Comment(1)
you are right, my initial search was too quick. +1 but I will go with coreutilsGramarye
E
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.

Evite answered 25/9, 2012 at 23:26 Comment(1)
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... ;)Grayish
B
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...

Bithynia answered 29/10, 2008 at 15:38 Comment(1)
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... ;-) )Gramarye
S
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.

Shimberg answered 4/8, 2012 at 1:28 Comment(0)
T
-1

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

Tiein answered 29/10, 2008 at 16:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.