<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: grep files in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352934#M192791</link>
    <description>Easiest&lt;BR /&gt;&lt;BR /&gt;grep -e cond1 -e cond2 -e cond3 -e cond file*&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 10 Aug 2004 03:39:52 GMT</pubDate>
    <dc:creator>Petr Simik_1</dc:creator>
    <dc:date>2004-08-10T03:39:52Z</dc:date>
    <item>
      <title>grep files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352930#M192787</link>
      <description>If I use grep "abc" ./* , it only grep the files that contains "abc" , if I want to add one more conditions , for example , the files contains "abc" AND "def" , how to do it ? thx.&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Aug 2004 21:24:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352930#M192787</guid>
      <dc:creator>peterchu</dc:creator>
      <dc:date>2004-08-09T21:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: grep files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352931#M192788</link>
      <description>You can use egrep, or grep -E:&lt;BR /&gt;&lt;BR /&gt;# egrep "abc|def" ./*&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;# grep -E "abc|def" ./*&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Dave</description>
      <pubDate>Mon, 09 Aug 2004 21:28:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352931#M192788</guid>
      <dc:creator>Dave Olker</dc:creator>
      <dc:date>2004-08-09T21:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: grep files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352932#M192789</link>
      <description>We can do it by using extended regular expresssions with -E option on grep or with egrep command.&lt;BR /&gt;&lt;BR /&gt;If you want to get the files contents which contain anyof the pattern "abc" or "def" then use &lt;BR /&gt;&lt;BR /&gt; grep -E "abc | def" ./*&lt;BR /&gt; egrep -i "abc | def" ./*&lt;BR /&gt;&lt;BR /&gt; -i used to ignore the case type&lt;BR /&gt;&lt;BR /&gt; And more we can do it with multiple -e option as,&lt;BR /&gt;&lt;BR /&gt; grep -ie abc -ie def filename&lt;BR /&gt;&lt;BR /&gt; It will do grep abe / def.&lt;BR /&gt;&lt;BR /&gt; If you want to print only the lines with abc and def then,&lt;BR /&gt;&lt;BR /&gt; grep -E 'abc' filename | grep -E 'def'&lt;BR /&gt;&lt;BR /&gt; It will do that.&lt;BR /&gt;&lt;BR /&gt; If you want to use patterns with - then use -e option&lt;BR /&gt; &lt;BR /&gt;Regards&lt;BR /&gt;Muthu</description>
      <pubDate>Mon, 09 Aug 2004 23:13:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352932#M192789</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-08-09T23:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: grep files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352933#M192790</link>
      <description>I think the answer is: &lt;BR /&gt;&lt;BR /&gt;grep -l abc * | xargs grep -l def&lt;BR /&gt;&lt;BR /&gt;Like Muthu writes, the established way of finding a file with both abc AND def ON ONE LINE is to chain greps: &lt;BR /&gt;&lt;BR /&gt;grep abc * | grep def&lt;BR /&gt;&lt;BR /&gt;or, if you know def follows abc:&lt;BR /&gt;&lt;BR /&gt;grep -E "abc.*def" *&lt;BR /&gt;&lt;BR /&gt;or, I suppose you could use a convoluted:&lt;BR /&gt;&lt;BR /&gt;grep -E "abc.*def|def.*abc" *&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;However, I think the author wants to list filenames for those fiels that contain both 'abc' and 'def', but not necesarilly on one line.&lt;BR /&gt;&lt;BR /&gt;So use:  grep -l abc x* | xargs grep -l def&lt;BR /&gt;&lt;BR /&gt;The first grep creates a list of filenames that contain abc, then xargs combines that list into agruments fro a second grep which again reads the whole file, not just the lines with 'abc'.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Bonus answer... in AWK:&lt;BR /&gt;&lt;BR /&gt;awk '//{if (FNR==1){a=d=x=0}} /abc/{a++} /def/{d++} {if (a&amp;amp;&amp;amp;d&amp;amp;&amp;amp;!x++) {print FILENAME}}' *&lt;BR /&gt;&lt;BR /&gt;And in PERL&lt;BR /&gt;&lt;BR /&gt;perl -e 'while ($f=shift @ARGV){$a=$d=0;open (F,"&amp;lt;$f");while (&lt;F&gt;){$a++ if /abc/; $d++ if /def/} print "$f\n" if ($a&amp;amp;&amp;amp;$d)}' *&lt;BR /&gt;&lt;BR /&gt;Both clear flags for each condition when a new file is started (in AWK we use FNR=1).&lt;BR /&gt;AWK limits printing FILENAME to once through a flag. PERL only tests at the end of the current file. Perl is easier to read (imho), but a 'lot' longer to write.&lt;BR /&gt;&lt;BR /&gt;Grins,&lt;BR /&gt;Hein&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;However, I think you are lookinf&lt;BR /&gt;&lt;/F&gt;</description>
      <pubDate>Tue, 10 Aug 2004 00:19:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352933#M192790</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-08-10T00:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: grep files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352934#M192791</link>
      <description>Easiest&lt;BR /&gt;&lt;BR /&gt;grep -e cond1 -e cond2 -e cond3 -e cond file*&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 10 Aug 2004 03:39:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352934#M192791</guid>
      <dc:creator>Petr Simik_1</dc:creator>
      <dc:date>2004-08-10T03:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: grep files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352935#M192792</link>
      <description>&lt;BR /&gt;Petr,&lt;BR /&gt;&lt;BR /&gt;Please help me understand how your solution would solve the problem stated: an AND condition.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Tue, 10 Aug 2004 08:19:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/grep-files/m-p/3352935#M192792</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-08-10T08:19:04Z</dc:date>
    </item>
  </channel>
</rss>

