可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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...
回答1:
You can use the original "wc", built for windows: it is part of the coreutils package. Get the most recent coreutils exe.
回答2:
Even easier, find /c
.
ex:
netstat -an | find /c "ESTABLISHED"
find /c
: Displays only the count of lines containing the string.
回答3:
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.
回答4:
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.
回答5:
Well, I'm sorry to disagree, but unxutils do have a wc.exe
Give it a try!
Cheers,
回答6:
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?
回答7:
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.
回答8:
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...
回答9:
getgnuwin32 facilitates downloading and installing of gnuwin32 (which certainly has wc utility).
回答10:
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.