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
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.
In Microsoft Word, click on the word count metric shown in the status bar.
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.
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!