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

StackOverflow https://stackoverflow.com/questions/247234

  •  05-07-2019
  •  | 
  •  

Question

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

Was it helpful?

Solution

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

OTHER TIPS

Even easier, find /c. ex:

netstat -an | find /c "ESTABLISHED"

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

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.

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.

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

Give it a try!

Cheers,

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?

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.

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

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top