Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Counting Characters with PowerShell

$
0
0

Summary: Use Windows PowerShell to count characters, words, and lines in a file.

Hey, Scripting Guy! Question How can I count the number of characters, words, and lines in a text file by using Windows PowerShell?

Hey, Scripting Guy! Answer Use the Measure-Object cmdlet; specify the -Line-Character, and -Word switched parameters; and use the Get-Content cmdlet to read the text file:

PS C:\> Get-Content C:\fso\ab.txt | measure -Line -Character -Word

                Lines                Words           Characters Property

                -----                -----           ---------- --------

                    3                   18                   73

If you want to ignore blank spaces when counting the characters, use the -IgnoreWhiteSpace switched parameter:

PS C:\> Get-Content C:\fso\ab.txt | measure -Line -Character -Word -IgnoreWhiteSpac

                Lines                Words           Characters Property

                -----                -----           ---------- --------

                    3                   18                   58 


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>