<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: recursively grep only certain files</title>
	<atom:link href="http://adammonsen.com/post/301/feed" rel="self" type="application/rss+xml" />
	<link>http://adammonsen.com/post/301</link>
	<description>blog and sundries of Adam Monsen</description>
	<lastBuildDate>Wed, 14 Jul 2010 19:18:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: adam</title>
		<link>http://adammonsen.com/post/301/comment-page-1#comment-11479</link>
		<dc:creator>adam</dc:creator>
		<pubDate>Sun, 30 Sep 2007 22:45:21 +0000</pubDate>
		<guid isPermaLink="false">http://adammonsen.com/post/301#comment-11479</guid>
		<description>While I&#039;m at it, here&#039;s one way to recurse down selected directory paths, searching within files for an arbitrary pattern:
&lt;blockquote&gt;&lt;pre&gt;
#!/bin/bash
find . -path &#039;*.svn*&#039; -prune -o -type f -print0 \\
    &#124; xargs -0 grep --col &quot;$1&quot;
&lt;/pre&gt;&lt;/blockquote&gt;
This is of course a bash script wherein the first argument is the pattern to search for within the files. I&#039;ve hardcoded it to skip any files including &lt;code&gt;&#039;.svn&#039;&lt;/code&gt; in their full path. I guess I&#039;ve also hardcoded where to start the search (the current directory).</description>
		<content:encoded><![CDATA[<p>While I&#8217;m at it, here&#8217;s one way to recurse down selected directory paths, searching within files for an arbitrary pattern:</p>
<blockquote><pre>
#!/bin/bash
find . -path '*.svn*' -prune -o -type f -print0 \\
    | xargs -0 grep --col "$1"
</pre>
</blockquote>
<p>This is of course a bash script wherein the first argument is the pattern to search for within the files. I&#8217;ve hardcoded it to skip any files including <code>'.svn'</code> in their full path. I guess I&#8217;ve also hardcoded where to start the search (the current directory).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: adam</title>
		<link>http://adammonsen.com/post/301/comment-page-1#comment-11476</link>
		<dc:creator>adam</dc:creator>
		<pubDate>Wed, 26 Sep 2007 15:44:48 +0000</pubDate>
		<guid isPermaLink="false">http://adammonsen.com/post/301#comment-11476</guid>
		<description>The first set of &lt;code&gt;egrep&lt;/code&gt;s you provide are fine if you know the exact directory depth of the source files.

&lt;code&gt;egrep&lt;/code&gt; regex syntax is fine, I&#039;m just more used to Perl-style regexes. The &lt;code&gt;-H&lt;/code&gt; is necessary if find only passes one filename to xargs, but you&#039;re right, it would be fine to omit that.

I agree the &lt;code&gt;grep&lt;/code&gt; args &lt;code&gt;-r&lt;/code&gt; paired with &lt;code&gt;--include&lt;/code&gt; are conceptually the same as using find and piping to &lt;code&gt;xargs&lt;/code&gt; and &lt;code&gt;grep&lt;/code&gt;, but you&#039;re firing up three processes when only one is necessary. Also, the command line is a little shorter. :)</description>
		<content:encoded><![CDATA[<p>The first set of <code>egrep</code>s you provide are fine if you know the exact directory depth of the source files.</p>
<p><code>egrep</code> regex syntax is fine, I&#8217;m just more used to Perl-style regexes. The <code>-H</code> is necessary if find only passes one filename to xargs, but you&#8217;re right, it would be fine to omit that.</p>
<p>I agree the <code>grep</code> args <code>-r</code> paired with <code>--include</code> are conceptually the same as using find and piping to <code>xargs</code> and <code>grep</code>, but you&#8217;re firing up three processes when only one is necessary. Also, the command line is a little shorter. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jason</title>
		<link>http://adammonsen.com/post/301/comment-page-1#comment-11473</link>
		<dc:creator>jason</dc:creator>
		<pubDate>Wed, 26 Sep 2007 05:52:48 +0000</pubDate>
		<guid isPermaLink="false">http://adammonsen.com/post/301#comment-11473</guid>
		<description>what about:
&lt;blockquote&gt;&lt;pre&gt;
egrep &#039;^#include +&lt;rpc&#039; */*.c
egrep &#039;^#include +&lt;rpc&#039; */*/*.c
egrep &#039;^#include +&lt;rpc&#039; */*/*/*.c
egrep &#039;^#include +&lt;rpc&#039; */*/*/*/*.c
&lt;/pre&gt;&lt;/blockquote&gt;

If you&#039;re in a hurry the command line substitution is pretty quick to add another splat slash to each one until you run out of directory depth. 

egrep has better support for regexes than plain &#039;ol grep does.

&lt;blockquote&gt;&lt;pre&gt;
find . -type f -name *.c -print0 &#124;xargs -0 egrep &#039;^#include +&lt;rpc&#039;
&lt;/pre&gt;&lt;/blockquote&gt;


I don&#039;t think you need the -P if you use egrep or the -H at all. I&#039;m not sure what you&#039;re getting out of the -r as find is passing xargs fully qualified paths to files that you&#039;re searching. You can&#039;t descend to a subdirectory of a file. 

Maybe I&#039;m missing something.
etc...</description>
		<content:encoded><![CDATA[<p>what about:</p>
<blockquote><pre>
egrep '^#include +&lt;rpc' */*.c
egrep '^#include +&lt;rpc' */*/*.c
egrep '^#include +&lt;rpc' */*/*/*.c
egrep '^#include +&lt;rpc' */*/*/*/*.c
</pre>
</blockquote>
<p>If you&#8217;re in a hurry the command line substitution is pretty quick to add another splat slash to each one until you run out of directory depth. </p>
<p>egrep has better support for regexes than plain &#8216;ol grep does.</p>
<blockquote><pre>
find . -type f -name *.c -print0 |xargs -0 egrep '^#include +&lt;rpc'
</pre>
</blockquote>
<p>I don&#8217;t think you need the -P if you use egrep or the -H at all. I&#8217;m not sure what you&#8217;re getting out of the -r as find is passing xargs fully qualified paths to files that you&#8217;re searching. You can&#8217;t descend to a subdirectory of a file. </p>
<p>Maybe I&#8217;m missing something.<br />
etc&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
