QuestionAccepted answer
Count the number of characters, words and lines in PowerShell
Mufa Sam
09 Mar 2021, 09:10 UTC
132.9K views1
In Linux we have the "wc" command which allows us to count the number of characters, words and lines in a file.
But do we have a similar cmdlet in PowerShell. The Measure-Object cmdlet I tried could only count the number of lines but not the characters and words.
1 answer
Accepted answer · original discussion
eyesec
Permalink12 Mar 2021, 09:10 UTC
Get-Content [FILENAME] | Measure-Object -Character
It counts the number of characters in the file.
Get-Content [FILENAME] | Measure-Object -Word
It counts the number of words in the file.
Get-Content [FILENAME] | Measure-Object -Line
It counts the number of lines in the file.
2 question comments
Use comments to ask for clarification. Post a solution as an answer.
Lee_DaileyPermalink
10 Mar 2021, 21:10 UTC
the
Measure-Object cmdlet CAN count lines, words, and chars. please add your code to the Question so we can see what needs changing.Liang ZhangPermalink
13 Mar 2021, 21:10 UTC
It works. Unfortunately,
Measure-Object seems to be much slower than wc.