<?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: Help with grep and if in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945434#M97622</link>
    <description>&lt;!--!*#--&gt;I always just use the exit code from grep:&lt;BR /&gt;&lt;BR /&gt;grep -q string $file&lt;BR /&gt;if [ $? -eq 0 ]&lt;BR /&gt;then&lt;BR /&gt;  echo "string is in $file"&lt;BR /&gt;else&lt;BR /&gt;  echo "string is not in $file"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Your friends here are:&lt;BR /&gt;&lt;BR /&gt;man test&lt;BR /&gt;man grep&lt;BR /&gt;</description>
    <pubDate>Thu, 15 Feb 2007 20:47:40 GMT</pubDate>
    <dc:creator>Daavid Turnbull</dc:creator>
    <dc:date>2007-02-15T20:47:40Z</dc:date>
    <item>
      <title>Help with grep and if</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945425#M97613</link>
      <description>I need code like this:&lt;BR /&gt;&lt;BR /&gt;if [[ grep string $file ]]&lt;BR /&gt;   then &lt;BR /&gt;      file contains string &lt;BR /&gt;   else&lt;BR /&gt;      file does not contain string &lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;I got this but it errors on "]]"&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Feb 2007 10:52:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945425#M97613</guid>
      <dc:creator>dictum9</dc:creator>
      <dc:date>2007-02-15T10:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Help with grep and if</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945426#M97614</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;if [ `grep string $file | wc -l` -gt 0 ]&lt;BR /&gt;..&lt;BR /&gt;&lt;BR /&gt;should work better.&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Feb 2007 10:59:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945426#M97614</guid>
      <dc:creator>Wouter Jagers</dc:creator>
      <dc:date>2007-02-15T10:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Help with grep and if</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945427#M97615</link>
      <description>try&lt;BR /&gt;&lt;BR /&gt;FOUND=`grep string $file`&lt;BR /&gt;if [[ -n $FOUND ]]&lt;BR /&gt;then&lt;BR /&gt;   contains value&lt;BR /&gt;else&lt;BR /&gt;   contains nothing&lt;BR /&gt;&lt;BR /&gt;-n is non zero check whereas -z is a zero check&lt;BR /&gt;&lt;BR /&gt;Cheers</description>
      <pubDate>Thu, 15 Feb 2007 11:02:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945427#M97615</guid>
      <dc:creator>gstonian</dc:creator>
      <dc:date>2007-02-15T11:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Help with grep and if</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945428#M97616</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;a=`grep 09 $file`&lt;BR /&gt;if [ -n "$a" ]&lt;BR /&gt; then &lt;BR /&gt; echo file contains string &lt;BR /&gt; else&lt;BR /&gt; echo file does not contain string &lt;BR /&gt; fi</description>
      <pubDate>Thu, 15 Feb 2007 11:06:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945428#M97616</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2007-02-15T11:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Help with grep and if</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945429#M97617</link>
      <description>If you don't actually need to keep the matching lines you can use grep's exit code.&lt;BR /&gt;&lt;BR /&gt;if grep 'string' "$file" 1&amp;gt;/dev/null 2&amp;gt;&amp;amp;1 ; then&lt;BR /&gt;        echo "$file contains string"&lt;BR /&gt;else&lt;BR /&gt;        echo "$file doesn't contain string, please add some"&lt;BR /&gt;fi</description>
      <pubDate>Thu, 15 Feb 2007 11:21:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945429#M97617</guid>
      <dc:creator>Heironimus</dc:creator>
      <dc:date>2007-02-15T11:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Help with grep and if</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945430#M97618</link>
      <description>I actually got it to work by removing the [[ and ]]&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Feb 2007 11:22:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945430#M97618</guid>
      <dc:creator>dictum9</dc:creator>
      <dc:date>2007-02-15T11:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Help with grep and if</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945431#M97619</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;The 'grep' filter will return zero (0) if there are matches; one (1) if not. Hence:&lt;BR /&gt;&lt;BR /&gt;# grep local /etc/hosts &amp;gt; /dev/null || echo "no matches!"&lt;BR /&gt;&lt;BR /&gt;...is a terse way to meet your goal.&lt;BR /&gt;&lt;BR /&gt;You can also count and return the number of matches with the '-c' switch. See the manpages for more information.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 15 Feb 2007 11:34:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945431#M97619</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-02-15T11:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: Help with grep and if</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945432#M97620</link>
      <description>You can improve Heironimus' solution by using grep -q, to not produce any output.</description>
      <pubDate>Thu, 15 Feb 2007 12:17:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945432#M97620</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-02-15T12:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Help with grep and if</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945433#M97621</link>
      <description>Unless there is a compelling reason to use the if statement, you could always use the following:&lt;BR /&gt;&lt;BR /&gt;# grep string file &amp;amp;&amp;amp; echo file contains string || echo file does not contain string&lt;BR /&gt;&lt;BR /&gt;~cheers</description>
      <pubDate>Thu, 15 Feb 2007 12:24:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945433#M97621</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-02-15T12:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with grep and if</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945434#M97622</link>
      <description>&lt;!--!*#--&gt;I always just use the exit code from grep:&lt;BR /&gt;&lt;BR /&gt;grep -q string $file&lt;BR /&gt;if [ $? -eq 0 ]&lt;BR /&gt;then&lt;BR /&gt;  echo "string is in $file"&lt;BR /&gt;else&lt;BR /&gt;  echo "string is not in $file"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Your friends here are:&lt;BR /&gt;&lt;BR /&gt;man test&lt;BR /&gt;man grep&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Feb 2007 20:47:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945434#M97622</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2007-02-15T20:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Help with grep and if</title>
      <link>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945435#M97623</link>
      <description>And another solution: grep -c which counts the matches:&lt;BR /&gt; &lt;BR /&gt;[ $(grep -c $STRING $FILE) = 0 ] \&lt;BR /&gt;&amp;amp;&amp;amp; echo no match || echo match</description>
      <pubDate>Thu, 15 Feb 2007 22:46:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/help-with-grep-and-if/m-p/3945435#M97623</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2007-02-15T22:46:12Z</dc:date>
    </item>
  </channel>
</rss>

