Find the Amount of Words, Chars and Lines in a Text File Using PowerShell

If you’re still using the good, old Notepad to craft essays or content for your Website, and want to know the number of characters used in a text file, here is a PowerShell cmdlet that will help.

PowerShell has a built-in cmdlet named “Measure-Object”. It calculates the property values of certain types of object.

Measure-Object performs three types of measurements, depending on the parameters in the command. The cmdlet can count objects and calculate the minimum, maximum, sum, and average of the numeric values.

For text objects, it can count and calculate the number of lines, words, and characters. This is exactly what we’re going to make use of, to get the summary of text based files.

Get the Line, Character and Word Count in a Text File

Start PowerShell, type or paste the following command and press ENTER.

Get-Content "D:\Net-Helpmsg.txt" | Measure-Object -Line -Character -Word

To ignore whitespace when counting the number of characters and words, use additional switch as below:

Get-Content "D:\Net-Helpmsg.txt" | Measure-Object -Line -Character -Word -IgnoreWhiteSpace

get word count in text file

In this example, the text file Net-Helpmsg.txt contains 24 lines, 333 words and 1839 characters.

Text editors and Word processors

Modern text editors such as Notepad++ and others show you the line count, number of characters and words used, in the status bar as you type. In Notepad++ you can view the stats by clicking Summary… from the View menu. The Summary dialog also shows the byte count, which isn’t shown in the Status bar.



get word count in text file

In Microsoft Word, click on the word count metric shown in the status bar.

get word count in text file

This opens the Word Count dialog that shows the file summary that includes number of pages, words, characters (with and without spaces), paragraphs and lines in that file.

get word count in text file

I’m sure vast majority of users would prefer third-party text editors or word processors with rich text formatting capabilities and other advanced features. However, users who still use the plain and simple Notepad to write articles, can find this post a tad useful.


One small request: If you liked this post, please share this?

One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
  • Pin it!
  • Share it to your favorite blog + Facebook, Reddit
  • Tweet it!
So thank you so much for your support. It won't take more than 10 seconds of your time. The share buttons are right below. :)

Ramesh Srinivasan is passionate about Microsoft technologies and he has been a consecutive ten-time recipient of the Microsoft Most Valuable Professional award in the Windows Shell/Desktop Experience category, from 2003 to 2012. He loves to troubleshoot and write about Windows. Ramesh founded Winhelponline.com in 2005.

Leave a Reply