<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Use a PowerShell Cmdlet to Count Files, Words, and Lines</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/10/09/use-a-powershell-cmdlet-to-count-files-words-and-lines.aspx</link><description>Summary: Learn how to use a powerful Windows PowerShell cmdlet to count words and lines in files, or to count files.</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Use a PowerShell Cmdlet to Count Files, Words, and Lines</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/10/09/use-a-powershell-cmdlet-to-count-files-words-and-lines.aspx#3458430</link><pubDate>Tue, 11 Oct 2011 12:02:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3458430</guid><dc:creator>Ed Wilson</dc:creator><description>&lt;p&gt;@JR you do not need to port the Unix type of utilities to Powershell. They are already available, all you need to do is to enable services for unix on your operating system (On Windows 7 it is called Subsystem for Unix based applications). One thing to keep in mind, all these Unix type of utilities are text based, they do not return objects like the PowerShell commands do. Therefore you will have to use regular expressions to parse the output from the commands. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3458430" width="1" height="1"&gt;</description></item><item><title>re: Use a PowerShell Cmdlet to Count Files, Words, and Lines</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/10/09/use-a-powershell-cmdlet-to-count-files-words-and-lines.aspx#3458354</link><pubDate>Tue, 11 Oct 2011 03:22:23 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3458354</guid><dc:creator>JR</dc:creator><description>&lt;p&gt;Why not port, Perl, Sed, Awk and bash into the powershell, seems to me that as a Unix guy you guys have attempted to reinvent the wheel, make it too complex.. I have hundreds of shell scripts, and am being forced to migrate to a Microsoft platform on a key piece of equipment. I cringe when I see how terribly complex your scripting is. Simple is better. &lt;/p&gt;
&lt;p&gt;In unix there is a simple command # wc &amp;nbsp;will count the words in a file. &lt;/p&gt;
&lt;p&gt;Seriously.. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3458354" width="1" height="1"&gt;</description></item><item><title>re: Use a PowerShell Cmdlet to Count Files, Words, and Lines</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/10/09/use-a-powershell-cmdlet-to-count-files-words-and-lines.aspx#3458316</link><pubDate>Mon, 10 Oct 2011 21:36:40 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3458316</guid><dc:creator>Craig Lussier</dc:creator><description>&lt;p&gt;@Ed - I should have taken a look at the Word Count in Word before posting - the numbers are off indeed. I made assumptions myself with the docx file and I wonder if it is taking into account any additional markup in the background of the document in addition to the text you see when creating/editing a document in Word. I will second your comment with reference to using COM to get the stats of a Word document - for anyone reading this the methods in this post are absolutely accurate for .txt files, however with Office files, please use Office Automation (COM) to ensure you get the correct numbers. Good conversation. Ed if you do find anything further on this please write a blog post - it will be interesting. Thanks for your comment Ed. Cheers. C.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3458316" width="1" height="1"&gt;</description></item><item><title>re: Use a PowerShell Cmdlet to Count Files, Words, and Lines</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/10/09/use-a-powershell-cmdlet-to-count-files-words-and-lines.aspx#3458273</link><pubDate>Mon, 10 Oct 2011 18:17:40 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3458273</guid><dc:creator>Ed Wilson</dc:creator><description>&lt;p&gt;@Craig Lussier I had not tried to use Measure-Object cmdlet with Microsoft Word documents because when I used Get-Content to attempt to read a Microsoft Word .DOC file, it made lots of beeping noises, displayed gibberish on the screen and literally locked up Windows PowerShell. Based upon that I had not attempted it again. However, I just tried Get-Content on a file and piped it to Measure-Object and it appeared to work. But when I looked at the numbers, there was a discrepancy. Measure-Object reported 1002 words on my .DOC file, and when I opened the word document in Microsoft Word, it said there were 1400 words ... so it was a huge difference. I wrote a script that uses the COM automation model to actually open each WORD document and get the statics ... and that is what I will stick with for now. Thank you for your comment because it caused me to reasses my assumptions. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3458273" width="1" height="1"&gt;</description></item><item><title>re: Use a PowerShell Cmdlet to Count Files, Words, and Lines</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/10/09/use-a-powershell-cmdlet-to-count-files-words-and-lines.aspx#3458268</link><pubDate>Mon, 10 Oct 2011 18:04:46 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3458268</guid><dc:creator>Ed Wilson</dc:creator><description>&lt;p&gt;@Klaus Measure-Object is cool. I am not sure what has changed about the blog layout. Let me check on this.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3458268" width="1" height="1"&gt;</description></item><item><title>re: Use a PowerShell Cmdlet to Count Files, Words, and Lines</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/10/09/use-a-powershell-cmdlet-to-count-files-words-and-lines.aspx#3458179</link><pubDate>Mon, 10 Oct 2011 08:14:49 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3458179</guid><dc:creator>Klaus Schulte</dc:creator><description>&lt;p&gt;Hi Ed,&lt;/p&gt;
&lt;p&gt;this is cool!&lt;/p&gt;
&lt;p&gt;Measure-Object takes away some tedious counting tasks from us I should remember to use it more often.&lt;/p&gt;
&lt;p&gt;Sometimes I&amp;#39;m still doing these things manually and this is really just an old habit that I should overcome now :-)&lt;/p&gt;
&lt;p&gt;Something completely different:&lt;/p&gt;
&lt;p&gt;Why does the new layout of this blog require scroll down in the browser so far?&lt;/p&gt;
&lt;p&gt;I really thought that the blog was empty last friday and didn&amp;#39;t recognize the enormous length of the scroll bar :-( Why is there so much empty, unused space in this page?&lt;/p&gt;
&lt;p&gt;Klaus&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3458179" width="1" height="1"&gt;</description></item><item><title>re: Use a PowerShell Cmdlet to Count Files, Words, and Lines</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/10/09/use-a-powershell-cmdlet-to-count-files-words-and-lines.aspx#3458145</link><pubDate>Mon, 10 Oct 2011 03:10:40 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3458145</guid><dc:creator>Craig Lussier</dc:creator><description>&lt;p&gt;In addition to text files, you can use the Measure-Object cmdlet against Microsoft Word documents as well... For example: Get-Content &amp;quot;c:\myWordDocument.docx&amp;quot; | measure-object -line -word -character&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3458145" width="1" height="1"&gt;</description></item></channel></rss>