<?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/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>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>MSDN Blog Postings  &amp;raquo; 2008 &amp;raquo; March &amp;raquo; 23</title><link>http://blogs.msdn.com/powershell/archive/2008/03/23/select-string-and-grep.aspx#8332575</link><pubDate>Sun, 23 Mar 2008 23:03:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8332575</guid><dc:creator>MSDN Blog Postings  » 2008 » March » 23</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://msdnrss.thecoderblogs.com/2008/03/23/"&gt;http://msdnrss.thecoderblogs.com/2008/03/23/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/powershell/archive/2008/03/23/select-string-and-grep.aspx#8332887</link><pubDate>Mon, 24 Mar 2008 05:53:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8332887</guid><dc:creator>David Mohundro</dc:creator><description>&lt;p&gt;I'm looking forward to v2 of Powershell with the context option (I think that's what it is) so that I can get more than just the line that was found but also +/- a line before and after.&lt;/p&gt;
&lt;p&gt;Also, I've seen some scripts that do highlighting (via Write-Host with a foreground color), but any chance we'll see official support for that?&lt;/p&gt;</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/powershell/archive/2008/03/23/select-string-and-grep.aspx#8333014</link><pubDate>Mon, 24 Mar 2008 07:56:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8333014</guid><dc:creator>james</dc:creator><description>&lt;p&gt;The best part about the emitted object is that you can get full access to the match details, match groups, etc. &amp;nbsp;Having had to do subsequent string parsing on the regex'd match, and finding out things like the string position of the regex match, or the what particular substring was matched was great!&lt;/p&gt;</description></item><item><title>@ Dave Mohundro</title><link>http://blogs.msdn.com/powershell/archive/2008/03/23/select-string-and-grep.aspx#8333552</link><pubDate>Mon, 24 Mar 2008 17:20:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8333552</guid><dc:creator>Marco Shaw</dc:creator><description>&lt;p&gt;Dave,&lt;/p&gt;
&lt;p&gt;The coloring you mention, via write-host, is directly built into the cmdlet, and you can use it with v1.&lt;/p&gt;
&lt;p&gt;PSH&amp;gt;write-host -fore yellow -back red &amp;quot;hello&amp;quot;&lt;/p&gt;</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/powershell/archive/2008/03/23/select-string-and-grep.aspx#8334362</link><pubDate>Tue, 25 Mar 2008 00:55:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8334362</guid><dc:creator>mike foley</dc:creator><description>&lt;p&gt;Jeffery,&lt;/p&gt;
&lt;p&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;thanks,&lt;/p&gt;
&lt;p&gt;mike&lt;/p&gt;
&lt;p&gt;axel::foley&lt;/p&gt;</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/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>PowerShellTeam</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;
</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/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;</description></item><item><title>--only-matches</title><link>http://blogs.msdn.com/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;</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/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;</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/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;</description></item><item><title>re: Select-String and Grep</title><link>http://blogs.msdn.com/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;</description></item><item><title>re: your wish is our command</title><link>http://blogs.msdn.com/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;</description></item><item><title>re: your wish is our command</title><link>http://blogs.msdn.com/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;</description></item></channel></rss>