<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.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>Select-String and Grep</title><link>http://blogs.msdn.com/b/powershell/archive/2008/03/23/select-string-and-grep.aspx</link><description>Dustin Marx has a blog entry where he compares Unix/Linux, PowerShell and DOS commands .&amp;#160; In it he says, &amp;quot; If there is one Unix command I would love to have in PowerShell, it is the grep command with its regular expression support. &amp;quot;&amp;#160;</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/b/powershell/archive/2008/03/23/select-string-and-grep.aspx#10218414</link><pubDate>Fri, 30 Sep 2011 01:47:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10218414</guid><dc:creator>WangFS</dc:creator><description>&lt;p&gt;#grep -o &amp;#39;\d+&amp;#39; &amp;nbsp; output &amp;nbsp;--only-matching part of a line func how to get?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10218414" width="1" height="1"&gt;</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/b/powershell/archive/2008/03/23/select-string-and-grep.aspx#10063011</link><pubDate>Thu, 16 Sep 2010 06:56:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10063011</guid><dc:creator>Clint Boessen</dc:creator><description>&lt;p&gt;Please see my howto for basic grep functionality under powershell:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://clintboessen.blogspot.com/2010/09/how-to-grep-in-powershell.html"&gt;clintboessen.blogspot.com/.../how-to-grep-in-powershell.html&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10063011" width="1" height="1"&gt;</description></item><item><title>re: your wish is our command</title><link>http://blogs.msdn.com/b/powershell/archive/2008/03/23/select-string-and-grep.aspx#9629568</link><pubDate>Tue, 19 May 2009 23:53:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9629568</guid><dc:creator>Hugo Eustaquio</dc:creator><description>&lt;p&gt;I want a md5sum to use with my scripts.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9629568" width="1" height="1"&gt;</description></item><item><title>re: your wish is our command</title><link>http://blogs.msdn.com/b/powershell/archive/2008/03/23/select-string-and-grep.aspx#9629555</link><pubDate>Tue, 19 May 2009 23:51:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9629555</guid><dc:creator>Hugo Eustáquio</dc:creator><description>&lt;p&gt;I want a md5sum for power shell, to integrate with my scripts.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9629555" width="1" height="1"&gt;</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/b/powershell/archive/2008/03/23/select-string-and-grep.aspx#9246832</link><pubDate>Mon, 22 Dec 2008 13:19:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9246832</guid><dc:creator>Luke Breuer</dc:creator><description>&lt;p&gt;Here are some performance numbers; when processing lines of text, PS appears to max out at around 4 lines/ms, whereas cmd.exe hits almost 3000 lines/ms for large files:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://luke.breuer.com/time/item/PowerShell_pipeline_performance/527.aspx"&gt;http://luke.breuer.com/time/item/PowerShell_pipeline_performance/527.aspx&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9246832" width="1" height="1"&gt;</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/b/powershell/archive/2008/03/23/select-string-and-grep.aspx#9243715</link><pubDate>Sat, 20 Dec 2008 12:06:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9243715</guid><dc:creator>Luke Breuer</dc:creator><description>&lt;p&gt;Grep is such a powerful and oft-used tool that I should think excellent support in v1 would be at the top of people's list. &amp;nbsp;I guess the focus was just on management more than processing text, but please note that processing text will be VERY IMPORTANT until everything is PS. &amp;nbsp;Until then, please give us a nice transition story. &amp;nbsp;I'll echo the --only-matches flag, the --max-count flag, the --no-filename flag, the --count flag, and the --invert-match flag. &amp;nbsp;Most of the features of grep are useful and I don't think supporting them would cost much in terms of benefit.&lt;/p&gt;
&lt;p&gt;As an aside, is there discussion somewhere of the poor performance when, say, tailing the last million lines of a file and piping it to grep? &amp;nbsp;I've resorted to cmd /c &amp;quot;tail ... | grep ...&amp;quot;, but that's kludgy, due to nesting of escapes and all that fun. &amp;nbsp;I tried a hack with lambdas [1], but it has two problems: it doesn't do string interpolation and some unknown problem I have yet to fully characterize. &amp;nbsp;Do you guys have any story for this?&lt;/p&gt;
&lt;p&gt;[1] &lt;a rel="nofollow" target="_new" href="http://luke.breuer.com/time/item/PowerShell_better_cmd_handling/481.aspx"&gt;http://luke.breuer.com/time/item/PowerShell_better_cmd_handling/481.aspx&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9243715" width="1" height="1"&gt;</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/b/powershell/archive/2008/03/23/select-string-and-grep.aspx#9075107</link><pubDate>Fri, 14 Nov 2008 20:51:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9075107</guid><dc:creator>Adrian</dc:creator><description>&lt;p&gt;I'm going to answer my own question&lt;/p&gt;
&lt;p&gt;ipconfig | select-string &amp;quot;IPv4 Address&amp;quot; | foreach { $_.Line | where { $_ -match &amp;quot;(\d{1,3}.){3}\d{1,3}&amp;quot; } | foreach { $matches[0] } }&lt;/p&gt;
&lt;p&gt;That was what I'm looking for but it's slightly more cumbersome than a property.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9075107" width="1" height="1"&gt;</description></item><item><title>--only-matches</title><link>http://blogs.msdn.com/b/powershell/archive/2008/03/23/select-string-and-grep.aspx#9074964</link><pubDate>Fri, 14 Nov 2008 20:39:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9074964</guid><dc:creator>Adrian</dc:creator><description>&lt;p&gt;What I find myself constantly wanting is a way to get the output equivalent of the --only-matches flag of grep&lt;/p&gt;
&lt;p&gt;The documentation tantalizes you by saying...&lt;/p&gt;
&lt;p&gt;Pattern: the string that was actually matched&lt;/p&gt;
&lt;p&gt;But it's not true - is the expression you used, which is what you'd expect.&lt;/p&gt;
&lt;p&gt;I'd really like to have the actual match text as a property.&lt;/p&gt;
&lt;p&gt;e.g. &lt;/p&gt;
&lt;p&gt;ipconfig | select-string &amp;quot;IPv4 Address&amp;quot; | foreach { $_.Line | select-string &amp;quot;(\d{1,3}.)\d{1,3}&amp;quot; | foreach { $_.Match } } | &amp;gt; list-of-ip-addresses.txt&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9074964" width="1" height="1"&gt;</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/b/powershell/archive/2008/03/23/select-string-and-grep.aspx#8931767</link><pubDate>Mon, 08 Sep 2008 04:49:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8931767</guid><dc:creator>PeterF</dc:creator><description>&lt;p&gt;The behaviour of select-string is very different from grep. Take this example using a pipe. In both a Linux OS and a Windows OS, I have three files. 2.txt found.txt and test.txt that contain the string &amp;quot;found&amp;quot;:&lt;/p&gt;
&lt;p&gt;UNIX/Linux bash shell:&lt;/p&gt;
&lt;p&gt;# ls&lt;/p&gt;
&lt;p&gt;2.txt &amp;nbsp;found.txt &amp;nbsp;test.txt&lt;/p&gt;
&lt;p&gt;Windows PowerShell:&lt;/p&gt;
&lt;p&gt;&amp;gt; ls&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Directory: Microsoft.PowerShell.Core\FileSystem::C:\aa\monad_doc\test_out&lt;/p&gt;
&lt;p&gt;Mode &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;LastWriteTime &amp;nbsp; &amp;nbsp; Length Name&lt;/p&gt;
&lt;p&gt;---- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;------------- &amp;nbsp; &amp;nbsp; ------ ----&lt;/p&gt;
&lt;p&gt;-a--- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8/09/2008 &amp;nbsp;10:25 AM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 49 2.txt&lt;/p&gt;
&lt;p&gt;-a--- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8/09/2008 &amp;nbsp;10:25 AM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 49 found.txt&lt;/p&gt;
&lt;p&gt;-a--- &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8/09/2008 &amp;nbsp;10:25 AM &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 49 test.txt&lt;/p&gt;
&lt;p&gt;Now I want to find out which files in the folder include the string &amp;quot;found&amp;quot; in their file names:&lt;/p&gt;
&lt;p&gt;UNIX/Linux bash shell:&lt;/p&gt;
&lt;p&gt;# ls | grep found&lt;/p&gt;
&lt;p&gt;found.txt&lt;/p&gt;
&lt;p&gt;Windows PowerShell:&lt;/p&gt;
&lt;p&gt;&amp;gt; ls | select-string found&lt;/p&gt;
&lt;p&gt;2.txt:1:found&lt;/p&gt;
&lt;p&gt;2.txt:2:his found&lt;/p&gt;
&lt;p&gt;2.txt:3:hisfound&lt;/p&gt;
&lt;p&gt;2.txt:4:her found&lt;/p&gt;
&lt;p&gt;2.txt:5:herfound&lt;/p&gt;
&lt;p&gt;found.txt:1:found&lt;/p&gt;
&lt;p&gt;found.txt:2:my found&lt;/p&gt;
&lt;p&gt;found.txt:3:myfound&lt;/p&gt;
&lt;p&gt;found.txt:4:your found&lt;/p&gt;
&lt;p&gt;found.txt:5:yourfound&lt;/p&gt;
&lt;p&gt;test.txt:1:found&lt;/p&gt;
&lt;p&gt;test.txt:2:my found&lt;/p&gt;
&lt;p&gt;test.txt:3:myfound&lt;/p&gt;
&lt;p&gt;test.txt:4:your found&lt;/p&gt;
&lt;p&gt;test.txt:5:yourfound&lt;/p&gt;
&lt;p&gt;bash interprets the command to mean &amp;quot;from all the file names returned by ls, return all instances of file names containing the string &amp;quot;found&amp;quot;&lt;/p&gt;
&lt;p&gt;PowerShell interprets the command to mean &amp;quot;in all the files returned by ls, return filename - colon - instance number per file (reading from the head of the file) - colon - line containing the string &amp;quot;found&amp;quot;&lt;/p&gt;
&lt;p&gt;Now let's dispense with the pipe and see what happens when we operate on one file only:&lt;/p&gt;
&lt;p&gt;UNIX/Linux bash shell:&lt;/p&gt;
&lt;p&gt;# grep found test.txt&lt;/p&gt;
&lt;p&gt;found&lt;/p&gt;
&lt;p&gt;my found&lt;/p&gt;
&lt;p&gt;myfound&lt;/p&gt;
&lt;p&gt;your found&lt;/p&gt;
&lt;p&gt;yourfound&lt;/p&gt;
&lt;p&gt;Windows PowerShell:&lt;/p&gt;
&lt;p&gt;&amp;gt; select-string found test.txt&lt;/p&gt;
&lt;p&gt;test.txt:1:found&lt;/p&gt;
&lt;p&gt;test.txt:2:my found&lt;/p&gt;
&lt;p&gt;test.txt:3:myfound&lt;/p&gt;
&lt;p&gt;test.txt:4:your found&lt;/p&gt;
&lt;p&gt;test.txt:5:yourfound&lt;/p&gt;
&lt;p&gt;bash interprets the command to mean &amp;quot;return all lines containing the string &amp;quot;found&amp;quot; in the file test.txt&amp;quot;&lt;/p&gt;
&lt;p&gt;PowerShell interprets the command to mean &amp;quot;return filename - colon - instance number (reading from the head of the file) - colon line containing the string &amp;quot;found&amp;quot; in the file test.txt&amp;quot;&lt;/p&gt;
&lt;p&gt;This is _just_the_beginning_ of the differences between grep and select-string.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8931767" width="1" height="1"&gt;</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/b/powershell/archive/2008/03/23/select-string-and-grep.aspx#8334934</link><pubDate>Tue, 25 Mar 2008 06:51:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8334934</guid><dc:creator>PowerShell Team</dc:creator><description>&lt;p&gt;&amp;gt; Does that mean one could use get-content -wait and pipe that to Select-String to watch a file and trigger an event when something matches?&lt;/p&gt;
&lt;p&gt;I have not tried that but I think you'll be able to connect those dots. &amp;nbsp;You'd need to run it in the background and then register for output events.&lt;/p&gt;
&lt;p&gt;Jeffrey Snover [MSFT]&lt;/p&gt;
&lt;p&gt;Windows Management Partner Architect&lt;/p&gt;
&lt;p&gt;Visit the Windows PowerShell Team blog at: &amp;nbsp; &amp;nbsp;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/PowerShell"&gt;http://blogs.msdn.com/PowerShell&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Visit the Windows PowerShell ScriptCenter at: &amp;nbsp;&lt;a rel="nofollow" target="_new" href="http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx"&gt;http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8334934" width="1" height="1"&gt;</description></item></channel></rss>