
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.thelinuxwiki.com/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.thelinuxwiki.com/index.php?action=history&amp;feed=atom&amp;title=Grep_examples</id>
		<title>Grep examples - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.thelinuxwiki.com/index.php?action=history&amp;feed=atom&amp;title=Grep_examples"/>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=Grep_examples&amp;action=history"/>
		<updated>2026-04-29T01:27:14Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.21.5</generator>

	<entry>
		<id>http://www.thelinuxwiki.com/index.php?title=Grep_examples&amp;diff=549&amp;oldid=prev</id>
		<title>Nighthawk: moved Grep expamples to Grep examples</title>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=Grep_examples&amp;diff=549&amp;oldid=prev"/>
				<updated>2013-09-23T21:03:36Z</updated>
		
		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/index.php?title=Grep_expamples&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Grep expamples (page does not exist)&quot;&gt;Grep expamples&lt;/a&gt; to &lt;a href=&quot;/index.php/Grep_examples&quot; title=&quot;Grep examples&quot;&gt;Grep examples&lt;/a&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 21:03, 23 September 2013&lt;/td&gt;
			&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Nighthawk</name></author>	</entry>

	<entry>
		<id>http://www.thelinuxwiki.com/index.php?title=Grep_examples&amp;diff=313&amp;oldid=prev</id>
		<title>Nighthawk: Pushed from Themanclub.</title>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=Grep_examples&amp;diff=313&amp;oldid=prev"/>
				<updated>2013-05-17T15:27:00Z</updated>
		
		<summary type="html">&lt;p&gt;Pushed from Themanclub.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;grep for multiple strings: &lt;br /&gt;
 '''grep -E &amp;quot;one|two|three&amp;quot;'''&lt;br /&gt;
grep for first pattern match only&lt;br /&gt;
 grep -m 1 &amp;lt;pattern&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For grepping line-by-line in a file filename, I often find these very useful&lt;br /&gt;
&lt;br /&gt;
Match pattern1 OR pattern2 in the same line:&lt;br /&gt;
 $ grep -E 'pattern1|pattern2' filename&lt;br /&gt;
&lt;br /&gt;
Match pattern1 AND pattern2 in the same line:&lt;br /&gt;
 $ grep -E 'pattern1.*pattern2' filename&lt;br /&gt;
The above command searches for pattern1 followed by pattern2. If the order does not matter or you want to search them in either order, then use the follwoing&lt;br /&gt;
 $ grep -E 'pattern1.*pattern2|pattern2.*pattern1' filename&lt;br /&gt;
The pipe enables the OR search which we saw earlier. Another option for this situation (i.e., AND search when the order is not important):&lt;br /&gt;
 $ grep -E 'pattern1' filename | grep -E 'pattern2'&lt;br /&gt;
which basically greps the STDOUT of the first grep.&lt;br /&gt;
&lt;br /&gt;
Match pattern1 AND pattern2, but NOT pattern3 in the same line:&lt;br /&gt;
 $ grep -E 'pattern1.*pattern2' filename | grep -Ev 'pattern3'&lt;br /&gt;
when the order of the first two patterns is important. When that order is NOT important:&lt;br /&gt;
 $ grep -E 'pattern1' filename | grep -E 'pattern2' | grep -Ev 'pattern3'&lt;br /&gt;
&lt;br /&gt;
Match pattern1 OR pattern2, but NOT pattern3 in the same line:&lt;br /&gt;
 $ grep -E 'pattern1|pattern2' filename | grep -Ev 'pattern3'&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux]]&lt;/div&gt;</summary>
		<author><name>Nighthawk</name></author>	</entry>

	</feed>