How do I do a "word count" command in Windows Command Prompt
Asked Answered
H

5

9

I know the command in Unix/Linux systems is "wc" but that doesn't work in Windows.

For reference the description for the UNIX word count command wc is:

Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. With no FILE, or when FILE is -, read standard input.

Hying answered 20/3, 2015 at 23:37 Comment(0)
C
4

The closest I know of is the PowerShell equivalent Measure-Object.

Get-Content filename.txt | Measure-Object -Word

Should give a word count similar to:

wc -w filename.txt

If you look at the help for Get-Content you will see it has aliases of gc, cat, and type and the alias for Measure-Object is measure so you could also type:

cat [filename] | measure -w
Carbide answered 21/3, 2015 at 16:1 Comment(1)
There are more examples in a later Q&A #59686319Farther
B
3

find command could be used in windows cmd to find line count (with the /c switch), word count etc.

http://rickardnobel.se/counting-lines-in-windows-command-prompt/

Bemire answered 30/3, 2016 at 10:3 Comment(0)
B
3

"Find" will be able to do the task similar to word count as RRM told.

Eg.

Query user | find /v /c ""

/v – Show any lines that don’t contain the string of words you specified. /c - Count the number of lines that matches the word in fine.

Query user | find /i "active" /c

/i - Ignore case /c - Count the number of lines that matches the word in fine.

Budget answered 5/3, 2018 at 18:56 Comment(3)
Please add correct tags for your question, like bash etc.Angelikaangelina
In this example is it looking for the word "active"? If I look for count of "fail" in "result.txt": Query user | find /i "fail" /c E:\tests\result.txtLanguishment
wc - print newline, word, and byte counts for each file. It doesn't look for occurrences of a specific word.Farther
Q
0

wc is part of the GNU Core Utils for Windows. I often install GnuWin32 utilities on Microsoft Windows systems to supply equivalents to the commands I use regularly on Linux and OS X systems.

Quantifier answered 21/3, 2015 at 2:20 Comment(1)
Awesome! I assume there's a version for 64 bit systems?Hying
B
0

You can use .Count

For example:

(findstr -i -s -m "example" *.txt).Count

This is the same as:

grep -l 'example' *.txt | wc -l
Berghoff answered 23/4, 2024 at 12:31 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.