Search code examples
linuxpowershellwc

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.


Solution

  • 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.