Technical questionAccepted answer
Count the number of characters, words and lines in PowerShell
Mufa Sam
Jan 10
0 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
PermalinkJan 17
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
Jan 10
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
Jul 13
It works. Unfortunately,
Measure-Object seems to be much slower than wc.