<?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: Search Multiple Words / String Pattern Using grep Command</title> <atom:link href="http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/feed/" rel="self" type="application/rss+xml" /><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/</link> <description>Every answer asks a more beautiful question.</description> <lastBuildDate>Fri, 10 Feb 2012 19:55:56 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Matt</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-67124</link> <dc:creator>Matt</dc:creator> <pubDate>Wed, 18 Jan 2012 10:44:46 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-67124</guid> <description>Thank you for this. I couldn&#039;t figure out why it wasn&#039;t working.</description> <content:encoded><![CDATA[<p>Thank you for this. I couldn&#8217;t figure out why it wasn&#8217;t working.</p> ]]></content:encoded> </item> <item><title>By: Ramon</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-65336</link> <dc:creator>Ramon</dc:creator> <pubDate>Thu, 08 Dec 2011 21:10:51 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-65336</guid> <description>Great info site.
I have a need to search a file looking for  dates and a string,  For example:
(Dec  2 13:25:27 name local5:warn&#124;warning vmdaemon[180412]: #415 Moved volume tape_1 #0055 (12345678) (abc123 from online to offline.). I need to search for a date and the &quot;online to offline&quot; string together. Also, with grep is it possible to do a date range in the search as oppose to a single date?</description> <content:encoded><![CDATA[<p>Great info site.<br
/> I have a need to search a file looking for  dates and a string,  For example:<br
/> (Dec  2 13:25:27 name local5:warn|warning vmdaemon[180412]: #415 Moved volume tape_1 #0055 (12345678) (abc123 from online to offline.). I need to search for a date and the &#8220;online to offline&#8221; string together. Also, with grep is it possible to do a date range in the search as oppose to a single date?</p> ]]></content:encoded> </item> <item><title>By: Abdulla</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-63705</link> <dc:creator>Abdulla</dc:creator> <pubDate>Wed, 19 Oct 2011 19:22:06 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-63705</guid> <description>Could you please help me regarding while connect putty Linux based logs like collect grep is working
tail -f test_log &#124; grep ‘\” 50[0234]‘ – working
tail -f test_log &#124; grep ‘\” 50[0234]‘ &#124; grep “404″ – not working
Any one help me on this regard? how to collect 1.500 to 504 2.404 alone.</description> <content:encoded><![CDATA[<p>Could you please help me regarding while connect putty Linux based logs like collect grep is working</p><p>tail -f test_log | grep ‘\” 50[0234]‘ – working</p><p>tail -f test_log | grep ‘\” 50[0234]‘ | grep “404″ – not working</p><p>Any one help me on this regard? how to collect 1.500 to 504 2.404 alone.</p> ]]></content:encoded> </item> <item><title>By: Jass</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-62837</link> <dc:creator>Jass</dc:creator> <pubDate>Mon, 26 Sep 2011 20:17:28 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-62837</guid> <description>/usr/xpg4/bin/grep -E &#039;error&#124;critical&#039; sample.txt
this works for me..</description> <content:encoded><![CDATA[<p>/usr/xpg4/bin/grep -E &#8216;error|critical&#8217; sample.txt</p><p>this works for me..</p> ]]></content:encoded> </item> <item><title>By: pop richards</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-62021</link> <dc:creator>pop richards</dc:creator> <pubDate>Tue, 30 Aug 2011 12:56:47 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-62021</guid> <description>&lt;strong&gt; grep -n &quot;$search1&quot;  . &#124; grep -n &quot;$search2&quot; &#124; grep -n &quot;$search3&quot; &lt;strong&gt;
after the first grep only statements &quot;search1&quot; will come. this is filtered by the next grep creating and AND condition.
this is a round about solution coming out the top of my mind. if i find a better solution i&#039;ll post it.</description> <content:encoded><![CDATA[<p><strong> grep -n &#8220;$search1&#8243;  . | grep -n &#8220;$search2&#8243; | grep -n &#8220;$search3&#8243; </strong><strong></p><p>after the first grep only statements &#8220;search1&#8243; will come. this is filtered by the next grep creating and AND condition.</p><p>this is a round about solution coming out the top of my mind. if i find a better solution i&#8217;ll post it.</strong></p> ]]></content:encoded> </item> <item><title>By: Mats</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-62019</link> <dc:creator>Mats</dc:creator> <pubDate>Tue, 30 Aug 2011 12:37:09 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-62019</guid> <description>Hi,
I have a requirement in which I would need to grep/find a line based on matching 3 different patterns. I know we can grep with -E multiple parameters seprated by pipe but this work Pipe (&#124;) as OR condition. My requirement is I want to use AND condition. It should show line where it satisfy both the parameter.
e.g. line in a file as --
10-Aug-2010 Hello, this is a new example for unix.
I need to show this line only when my grep command matches all 3 words
this, new, unix How to right such grep command ?</description> <content:encoded><![CDATA[<p>Hi,</p><p>I have a requirement in which I would need to grep/find a line based on matching 3 different patterns. I know we can grep with -E multiple parameters seprated by pipe but this work Pipe (|) as OR condition. My requirement is I want to use AND condition. It should show line where it satisfy both the parameter.<br
/> e.g. line in a file as &#8211;<br
/> 10-Aug-2010 Hello, this is a new example for unix.<br
/> I need to show this line only when my grep command matches all 3 words<br
/> this, new, unix How to right such grep command ?</p> ]]></content:encoded> </item> <item><title>By: Saravanan</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-61799</link> <dc:creator>Saravanan</dc:creator> <pubDate>Tue, 23 Aug 2011 04:43:38 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-61799</guid> <description>hi, i want to grep the lines which has Eg:&quot;uat&quot; string  in the but not &quot;#&quot; string in the line.. can anyone help me out in this????</description> <content:encoded><![CDATA[<p>hi, i want to grep the lines which has Eg:&#8221;uat&#8221; string  in the but not &#8220;#&#8221; string in the line.. can anyone help me out in this????</p> ]]></content:encoded> </item> <item><title>By: anoop</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-61049</link> <dc:creator>anoop</dc:creator> <pubDate>Wed, 27 Jul 2011 09:55:36 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-61049</guid> <description>use
grep &#039;rob&#039; &#124; grep &#039;bob&#039;</description> <content:encoded><![CDATA[<p>use<br
/> grep &#8216;rob&#8217; | grep &#8216;bob&#8217;</p> ]]></content:encoded> </item> <item><title>By: Hemal</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-60538</link> <dc:creator>Hemal</dc:creator> <pubDate>Thu, 07 Jul 2011 12:08:05 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-60538</guid> <description>Fantastic !! I had a scenario where in I had to pick up lines from a log file based on a word. Unfortunately I had 1000 such words and so it would have been difficult to find 1000 lines. But this solution really helped. Thanks.</description> <content:encoded><![CDATA[<p>Fantastic !! I had a scenario where in I had to pick up lines from a log file based on a word. Unfortunately I had 1000 such words and so it would have been difficult to find 1000 lines. But this solution really helped. Thanks.</p> ]]></content:encoded> </item> <item><title>By: Anthony</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-60137</link> <dc:creator>Anthony</dc:creator> <pubDate>Mon, 20 Jun 2011 22:32:14 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-60137</guid> <description>That won&#039;t work if you need to check if word 1 and word2 are anywhere in the file, because the first grep returns the matching line, so the second grep would only match if both words were on the same line.</description> <content:encoded><![CDATA[<p>That won&#8217;t work if you need to check if word 1 and word2 are anywhere in the file, because the first grep returns the matching line, so the second grep would only match if both words were on the same line.</p> ]]></content:encoded> </item> <item><title>By: richardspop</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-59459</link> <dc:creator>richardspop</dc:creator> <pubDate>Tue, 17 May 2011 12:11:08 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-59459</guid> <description>its
grep -n &quot;error:*&quot; filename
since its one file -r is not necessary.</description> <content:encoded><![CDATA[<p>its<br
/> grep -n &#8220;error:*&#8221; filename</p><p>since its one file -r is not necessary.</p> ]]></content:encoded> </item> <item><title>By: richardspop</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-59458</link> <dc:creator>richardspop</dc:creator> <pubDate>Tue, 17 May 2011 12:09:28 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-59458</guid> <description>do u have any keyword to identify the error message??
for eg. if the keyword is &#039;error:&#039;
then
grep -rn &quot;error:*&quot; </description> <content:encoded><![CDATA[<p>do u have any keyword to identify the error message??<br
/> for eg. if the keyword is &#8216;error:&#8217;</p><p>then</p><p>grep -rn &#8220;error:*&#8221;</p> ]]></content:encoded> </item> <item><title>By: nithya</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-59456</link> <dc:creator>nithya</dc:creator> <pubDate>Tue, 17 May 2011 10:09:31 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-59456</guid> <description>hi.
how to search a single line using grep command..
for example a file having 100 lines in that 100 line only one error line is there.
how do i retrive that single line using grep command.. i don&#039;t know in which line in that error msg and like that error msg many of the lines in that file.. how do i find using &#039;Grep&#039; command..</description> <content:encoded><![CDATA[<p>hi.<br
/> how to search a single line using grep command..<br
/> for example a file having 100 lines in that 100 line only one error line is there.</p><p>how do i retrive that single line using grep command.. i don&#8217;t know in which line in that error msg and like that error msg many of the lines in that file.. how do i find using &#8216;Grep&#8217; command..</p> ]]></content:encoded> </item> <item><title>By: ajorpheus</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-59362</link> <dc:creator>ajorpheus</dc:creator> <pubDate>Wed, 11 May 2011 16:25:18 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-59362</guid> <description>@Kumar and others
To search for multiple strings in a file try doing this :
&lt;pre&gt;
grep -il &quot;String1&quot; &quot;PATH-OF-FILE&quot; &#124; xargs -I % grep -H &quot;String2&quot; % &#124; xargs -I % grep -H &quot;String3&quot; %
&lt;/pre&gt;
For eg:
Let&#039;s say I want to search for all those &lt;strong&gt;log4j.xml&lt;/strong&gt; files which have the words &lt;strong&gt;CONSOLE&lt;/strong&gt; and &lt;strong&gt;ASYNC&lt;/strong&gt; in them .. then this is what I would do :
&lt;pre&gt;
find &quot;/cygdrive/e/MyDocs/Downloads/work/OATS Domain related/&quot; -iname &quot;log4j*.xml&quot; &#124; xargs -I % grep -ilr &quot;CONSOLE&quot; &quot;%&quot; &#124; xargs -I % grep -H &quot;ASYNC&quot; %
&lt;/pre&gt;
Cheers!</description> <content:encoded><![CDATA[<p>@Kumar and others</p><p>To search for multiple strings in a file try doing this :</p><pre>
grep -il "String1" "PATH-OF-FILE" | xargs -I % grep -H "String2" % | xargs -I % grep -H "String3" %
</pre><p>For eg:<br
/> Let&#8217;s say I want to search for all those <strong>log4j.xml</strong> files which have the words <strong>CONSOLE</strong> and <strong>ASYNC</strong> in them .. then this is what I would do :</p><pre>
find "/cygdrive/e/MyDocs/Downloads/work/OATS Domain related/" -iname "log4j*.xml" | xargs -I % grep -ilr "CONSOLE" "%" | xargs -I % grep -H "ASYNC" %
</pre><p>Cheers!</p> ]]></content:encoded> </item> <item><title>By: kumar</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-57695</link> <dc:creator>kumar</dc:creator> <pubDate>Mon, 25 Apr 2011 09:10:04 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-57695</guid> <description>Hi,
I need to list the files which contains the 3 strings
&lt;Tax
&lt;Source
HEAD
These all 3 strings may be in different lines.
Thanks, Kumar</description> <content:encoded><![CDATA[<p>Hi,<br
/> I need to list the files which contains the 3 strings<br
/> &lt;Tax<br
/> &lt;Source<br
/> HEAD<br
/> These all 3 strings may be in different lines.</p><p>Thanks, Kumar</p> ]]></content:encoded> </item> <item><title>By: karatedog</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-56400</link> <dc:creator>karatedog</dc:creator> <pubDate>Sun, 20 Mar 2011 20:03:31 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-56400</guid> <description>First: grep is a single line utility. And because &quot;5)&quot; is on two lines, grep will find them, because it walks down the lines, and matches them to your rules, period.
Second: what grep finds, that &#039;entire&#039; line will be displayed. So it is not possible to cut the &quot;5)&quot; from the beginning of the line, and display the rest.
If you want to find &quot;ram&quot; and after that the next &quot;5)&quot;, you need to use some utility that allows you to implement some logic. Like awk.
However if you can ensure that &quot;5)...&quot; will be after the found line - like &quot;ram&quot; - then you can use the &#039;after context&#039; feature of grep, whic displayes the matching lines PLUS some line after that.</description> <content:encoded><![CDATA[<p>First: grep is a single line utility. And because &#8220;5)&#8221; is on two lines, grep will find them, because it walks down the lines, and matches them to your rules, period.<br
/> Second: what grep finds, that &#8216;entire&#8217; line will be displayed. So it is not possible to cut the &#8220;5)&#8221; from the beginning of the line, and display the rest.<br
/> If you want to find &#8220;ram&#8221; and after that the next &#8220;5)&#8221;, you need to use some utility that allows you to implement some logic. Like awk.<br
/> However if you can ensure that &#8220;5)&#8230;&#8221; will be after the found line &#8211; like &#8220;ram&#8221; &#8211; then you can use the &#8216;after context&#8217; feature of grep, whic displayes the matching lines PLUS some line after that.</p> ]]></content:encoded> </item> <item><title>By: vaibhav</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-56395</link> <dc:creator>vaibhav</dc:creator> <pubDate>Sun, 20 Mar 2011 09:28:03 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-56395</guid> <description>hi
I have to grep exact line in file
for eg : file name test.txt includes
ram
5) 1,2,3
sohan
5) 6,7,8
so i want to grep ram and 5 so the output shud be
ram
1,2,3
should not be
ram
1,2,3
6,7,8</description> <content:encoded><![CDATA[<p>hi</p><p>I have to grep exact line in file<br
/> for eg : file name test.txt includes<br
/> ram<br
/> 5) 1,2,3<br
/> sohan<br
/> 5) 6,7,8</p><p>so i want to grep ram and 5 so the output shud be<br
/> ram<br
/> 1,2,3</p><p>should not be<br
/> ram<br
/> 1,2,3<br
/> 6,7,8</p> ]]></content:encoded> </item> <item><title>By: richardspop</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-56191</link> <dc:creator>richardspop</dc:creator> <pubDate>Tue, 08 Mar 2011 10:07:13 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-56191</guid> <description>try
$grep -r “word1″  /Folder/subfolder/ &#124; grep “word2″ &gt; search.log</description> <content:encoded><![CDATA[<p>try<br
/> $grep -r “word1″  /Folder/subfolder/ | grep “word2″ &gt; search.log</p> ]]></content:encoded> </item> <item><title>By: Ritika</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-52573</link> <dc:creator>Ritika</dc:creator> <pubDate>Thu, 16 Dec 2010 08:31:23 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-52573</guid> <description>How to search multiple words in separate lines, inside a directory including sub-directory? Pls. give easy example.
I tried $grep -r &quot;word1&quot; &#124;grep -r &quot;word2&quot; /Folder/subfolder/ &gt; search.log</description> <content:encoded><![CDATA[<p>How to search multiple words in separate lines, inside a directory including sub-directory? Pls. give easy example.<br
/> I tried $grep -r &#8220;word1&#8243; |grep -r &#8220;word2&#8243; /Folder/subfolder/ &gt; search.log</p> ]]></content:encoded> </item> <item><title>By: Dr.Death</title><link>http://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/#comment-50077</link> <dc:creator>Dr.Death</dc:creator> <pubDate>Wed, 13 Oct 2010 10:57:08 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/?p=1047#comment-50077</guid> <description>try
echo &quot;hi rob, where is bob?&quot; &#124; grep -E -o &quot;rob&#124;bob&quot;
it should return:
rob
bob</description> <content:encoded><![CDATA[<p>try<br
/> echo &#8220;hi rob, where is bob?&#8221; | grep -E -o &#8220;rob|bob&#8221;</p><p>it should return:<br
/> rob<br
/> bob</p> ]]></content:encoded> </item> </channel> </rss>
