<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The eflow blog &#187; grep</title>
	<atom:link href="http://blog.eflow.org/archives/tag/grep/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.eflow.org</link>
	<description>Insert some amazingly witty tagline here</description>
	<lastBuildDate>Fri, 23 Apr 2010 03:19:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Grep Across Multiple Lines</title>
		<link>http://blog.eflow.org/archives/76</link>
		<comments>http://blog.eflow.org/archives/76#comments</comments>
		<pubDate>Sat, 20 Sep 2008 13:28:57 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[babble]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://blog.eflow.org/?p=76</guid>
		<description><![CDATA[I struggled for a long while to get the unix &#8220;grep&#8221; program to do a true multi word search.  However, grep merely searches within lines, so only files that had all words in the phrase on the same line would be returned.  I wanted to know which files in the current folder contained the words [...]]]></description>
			<content:encoded><![CDATA[<p>I struggled for a long while to get the unix &#8220;grep&#8221; program to do a true multi word search.  However, grep merely searches within lines, so only files that had <span style="text-decoration: underline;">all</span> words in the phrase on the <span style="text-decoration: underline;">same</span> line would be returned.  I wanted to know which files in the current folder contained the words &#8220;Reuben&#8221;, &#8220;Onida&#8221; and &#8220;Cornelius&#8221; anywhere (and in any order) within them.</p>
<p>The solution turned out to be to grep three times and pipe each result into the next:</p>
<blockquote><p>grep -l Reuben * | xargs grep -l Onida | xargs grep -l Cornelius</p></blockquote>
<p>The first <code>grep -l Reuben *</code> returns all file names that contain the word &#8220;Reuben&#8221;.  Piping that to xargs makes the second argument essentially <code>grep -l Onida file1 file2 file3 file4</code> etc.  This chaining can go on for as many search phrases as you have.  The final output is a list of files that contain every word in your search phrase.</p>
 <img src="http://blog.eflow.org/wp-content/plugins/feed-statistics.php?view=1&post_id=76" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.eflow.org/archives/76/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
