{"id":4426,"date":"2016-10-23T09:39:41","date_gmt":"2016-10-23T04:09:41","guid":{"rendered":"http:\/\/198.58.113.91\/blog\/?p=4426"},"modified":"2019-05-12T02:53:34","modified_gmt":"2019-05-12T02:53:34","slug":"find-amount-words-lines-chars-text-file-powershell","status":"publish","type":"post","link":"https:\/\/www.winhelponline.com\/blog\/find-amount-words-lines-chars-text-file-powershell\/","title":{"rendered":"Find the Amount of Words, Chars and Lines in a Text File Using PowerShell"},"content":{"rendered":"<p>If you&#8217;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.<!--more--><\/p>\n<p>PowerShell has a built-in cmdlet named &#8220;Measure-Object&#8221;. It calculates the property values of certain types of object.<\/p>\n<p><em><a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/hh849965.aspx?f=255&amp;MSPPError=-2147217396\" target=\"_blank\" rel=\"noopener noreferrer\">Measure-Object<\/a> 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.<\/em><\/p>\n<p>For text objects, it can count and calculate the number of lines, words, and characters. This is exactly what we&#8217;re going to make use of, to get the summary of text based files.<\/p>\n<h2>Get the Line, Character and Word Count in a Text File<\/h2>\n<p>Start PowerShell, type or paste the following command and press ENTER.<\/p>\n<pre>Get-Content \"D:\\Net-Helpmsg.txt\" | Measure-Object -Line -Character -Word<\/pre>\n<p>To ignore whitespace when counting the number of characters and words, use additional switch as below:<\/p>\n<pre>Get-Content \"D:\\Net-Helpmsg.txt\" | Measure-Object -Line -Character -Word -IgnoreWhiteSpace<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/10\/get-word-count-1.png\" alt=\"get word count in text file\" width=\"618\" height=\"123\" class=\"aligncenter size-full wp-image-4427\" \/><\/p>\n<p>In this example, the text file Net-Helpmsg.txt contains 24 lines, 333 words and 1839 characters.<\/p>\n<h3>Text editors and Word processors<\/h3>\n<p>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&#8230; from the View menu. The Summary dialog also shows the byte count, which isn&#8217;t shown in the Status bar.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/10\/get-word-count-4.png\" alt=\"get word count in text file\" width=\"372\" height=\"390\" class=\"aligncenter size-full wp-image-4430\" \/><\/p>\n<p>In Microsoft Word, click on the word count metric shown in the status bar.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/10\/get-word-count-2.png\" alt=\"get word count in text file\" width=\"621\" height=\"257\" class=\"aligncenter size-full wp-image-4429\" \/><\/p>\n<p>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.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/10\/get-word-count-3.png\" alt=\"get word count in text file\" width=\"256\" height=\"217\" class=\"aligncenter size-full wp-image-4428\" \/><\/p>\n<p>I&#8217;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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[8],"tags":[],"class_list":["post-4426","post","type-post","status-publish","format-standard","hentry","category-windows-10"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10243,"url":"https:\/\/www.winhelponline.com\/blog\/install-module-command-was-found-in-the-module-powershellget\/","url_meta":{"origin":4426,"position":0},"title":"Install-Module command was found in the module PowerShellGet","author":"Ramesh","date":"July 8, 2019","format":false,"excerpt":"PowerShell's Install-Module cmdlet downloads one or more modules from a repository and installs them on the local computer. But, when you run Install-Module, you may get the following error: Install-Module : The 'Install-Module' command was found in the module 'PowerShellGet', but the module could not be loaded. For more information,\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"install-module command not found","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/powershell-install-module-error-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/powershell-install-module-error-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/powershell-install-module-error-1.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":6699,"url":"https:\/\/www.winhelponline.com\/blog\/brightness-resets-50-percent-after-reboot-windows-10\/","url_meta":{"origin":4426,"position":1},"title":"[Fix] Brightness Resets to 50% After Restarting Windows 10 (v1809)","author":"Ramesh","date":"October 26, 2018","format":false,"excerpt":"After installing Windows 10 feature update v1809, the screen brightness gets reset to 50% after every shutdown or restart. This seems to be yet another bug in the 1809 update. This post tells you how to fix\/workaround the screen brightness reset problem in your Windows 10 1809 computer. [Fix] Brightness\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"powershell set brightness cmdlet task scheduler","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2018\/10\/powershell-screen-brightness-set-prompt.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3922,"url":"https:\/\/www.winhelponline.com\/blog\/empty-recycle-bin-task-scheduler-powershell-clear-recyclebin-nircmd\/","url_meta":{"origin":4426,"position":2},"title":"Empty Recycle Bin Automatically Using Task Scheduler or Storage Sense","author":"Ramesh","date":"August 31, 2016","format":false,"excerpt":"You can use it to clear the Recycle Bin at a specified time or regular intervals with Task Scheduler using a PowerShell command. Alternately, you can also use Storage Settings (a.k.a. Storage Sense) to clear the files from Recycle Bin that are older than a certain number of days. This\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"empty recycle bin - storage settings or storage sense","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/storage-settings-cleanup-enable.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/storage-settings-cleanup-enable.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/storage-settings-cleanup-enable.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/storage-settings-cleanup-enable.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":28839,"url":"https:\/\/www.winhelponline.com\/blog\/cant-open-cmd-after-uninstalling-python-anaconda\/","url_meta":{"origin":4426,"position":3},"title":"Can&#8217;t Open CMD.exe After Uninstalling Python\/Anaconda; Exit Code 1","author":"Ramesh","date":"September 29, 2022","format":false,"excerpt":"After uninstalling Python\/Anaconda on your Windows computer, Command Prompt may not open. When you run cmd.exe, it flashes on the screen and immediately quits. Also, running DISM and SFC (to repair corrupt system files), repairing Windows installation, and running a thorough malware scan may not fix the issue. Also, when\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"vscode cmd.exe error 1","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2022\/09\/vscode-cmd-error-code-1.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":30783,"url":"https:\/\/www.winhelponline.com\/blog\/dism-exe-not-recognized-cmdlet-ps\/","url_meta":{"origin":4426,"position":4},"title":"[Error] Dism.exe is not recognized as the name of a cmdlet","author":"Ramesh","date":"December 11, 2022","format":false,"excerpt":"When you run a DISM.exe command-line in PowerShell, the command may not be recognized. The following error is shown when you do so: dism.exe : The term 'dism.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"dism.exe not recognized - add system32 to PATH","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2022\/12\/dism-system32-path-missing-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2022\/12\/dism-system32-path-missing-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2022\/12\/dism-system32-path-missing-1.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":10618,"url":"https:\/\/www.winhelponline.com\/blog\/find-the-total-execution-time-of-command-program-windows\/","url_meta":{"origin":4426,"position":5},"title":"Find the Total Execution Time of a Command or Program in Windows","author":"Ramesh","date":"August 5, 2019","format":false,"excerpt":"You may sometimes want to to find the total execution time of a command or program you run. To optimize a script or program, it's essential to know how long does it take for it to complete execution. This helps you compare the total run time of Program A vs.\u2026","rel":"","context":"In &quot;Utilities&quot;","block_context":{"text":"Utilities","link":"https:\/\/www.winhelponline.com\/blog\/category\/utilities\/"},"img":{"alt_text":"measure total execution time of a command or program","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/08\/find-execution-time-measure-4.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/08\/find-execution-time-measure-4.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/08\/find-execution-time-measure-4.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/4426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/comments?post=4426"}],"version-history":[{"count":0,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/4426\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/media?parent=4426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/categories?post=4426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/tags?post=4426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}