Skip to content
Advertisement

Count the number of characters, words and lines in PowerShell

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement