您知道 Windows 上的 wc(unix 字数统计命令)的类似程序吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/247234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:38:32  来源:igfitidea点击:

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

windowscmd

提问by VonC

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

快速搜索给了我tawbaware wc,但它不接受 stdout 作为输入流,这意味着我不能在DOS会话中使用管道。

Note:

笔记:

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

我无法安装 cygwin 或使用 powershell(这将允许使用“ |foreach-object {(get-content $_).count}”)

unxutilsand and gnuwin32Packages might have this feature...

unxutils和和的GnuWin32包可能有这个功能...

采纳答案by florin

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

您可以使用为 Windows 构建的原始“wc”:它是coreutils包的一部分。获取最新的 coreutils exe

回答by jeff drake

Even easier, find /c. ex:

更容易,find /c. 前任:

netstat -an | find /c "ESTABLISHED"

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

find /c: 只显示包含字符串的行数。

回答by Martin Beckett

For unix tools on windows your options are:

对于 Windows 上的 unix 工具,您的选择是:

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

msys- 类似于 unixtools,最初只是一些与 mingw(gcc 的本机版本)一起需要的构建工具,现在几乎拥有所有的 cygwin 工具

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

cygwin- 几乎适用于 unix 的所有东西,复杂的安装并且需要一个 dll 来提供 unix api。混合使用不同版本的 cygwin.dll 构建的工具可能会出现问题

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

Unixtools- 不是 cygwin 提供的所有工具,而是本地编译的

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.

ch- 几乎所有的 unix 工具,本地编译。还有一个包含“c”解释器的外壳。标准版本是免费的(啤酒)但不是开源的。

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

uwin- 没有 ATT,如果你喜欢那种东西,包括 korn shell。

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

mks是 unix 工具的商业端口。鉴于可用的免费版本,相当昂贵。

回答by Dan S.

Try:

尝试:

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

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

此命令提供包含搜索字符串的所有行的计数。测试它,我看到一个问题,它似乎没有计算文件末尾的空行。

回答by Vinzz

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

好吧,我很抱歉不同意,但unxutils确实有一个 wc.exe

Give it a try!

试一试!

Cheers,

干杯,

回答by Miguel Ping

My unxutilspack has word count:

我的unxutils包有字数统计:

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

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.exeis available. Are you looking for something that wc.exedoes not handle?

此外,unxutils 页面表明wc.exe可用。您是否正在寻找wc.exe无法处理的内容?

回答by Miguel Ping

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

这里有另外两种(纯 Windows CMD)方法来计算 git 日志中的行数:

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.

第一个的优点是你最终得到了一个环境变量中的值,你可以用它来做任何事情。但是对于大文件它可能会运行缓慢。

回答by Miguel Ping

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

还有WinXs 4.2,它是共享软件,因此您可以查看它是否可以满足您的需求。

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

你能为此安装一种脚本语言吗?这可能是矫枉过正,但如果它以最少的大惊小怪完成工作......

回答by Miguel Ping

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.

我发现了这个线程,并被仅使用 Windows 内置工具模拟 wc 的创新解决方案所吸引。这激发了我对字符数需求的回答,以便我可以在与 Web 表单字段的最大字符的战斗中获胜警告。

If you want wc -cwhich 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.

如果您想要wc -c提供字节计数,您可以在 Windows 中使用DEBUG,这是一个 DOS 实用程序(未在 HELP 命令中列出)。字符数应等于字节数减去行数乘以换行符的大小,对于 Unix,换行符是一个换行符 ('\n') 或两个字符,回车 + 换行符('\cr' 和 '\lf' 或 ' \0Dh' '0Ah' 用于 DOS 纯文本文件。

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

字符数 = 字节数 - (行数 * 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:

为此,请打开命令行窗口(开始->运行->打开:“cmd”),对纯文本文件运行调试并检查包含加载文件长度的 CX 寄存器:

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

调试 [路径名] -rcx CX [十六进制文件长度]:-q

Then run find on the file:

然后在文件上运行 find :

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

find /v /c "notlikelystring" ---------- [路径名]: [行数]

And apply the formula.

并应用公式。

回答by jfs

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

getgnuwin32有助于下载和安装gnuwin32(当然有 wc 实用程序)。