<?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: search excat string in another string (grep &amp;quot;fails&amp;quot;) in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211112#M91723</link>
    <description>&lt;!--!*#--&gt;&amp;gt; [...] command "grep" shows the wrong result:&lt;BR /&gt;&lt;BR /&gt;What (would you say) is the "right" result?&lt;BR /&gt;Would adding some spaces do what you want?&lt;BR /&gt;&lt;BR /&gt;echo " ${STRINGS} " | grep " ${search_string} "</description>
    <pubDate>Thu, 05 Jun 2008 14:05:14 GMT</pubDate>
    <dc:creator>Steven Schweda</dc:creator>
    <dc:date>2008-06-05T14:05:14Z</dc:date>
    <item>
      <title>search excat string in another string (grep "fails")</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211106#M91717</link>
      <description>hello,&lt;BR /&gt;&lt;BR /&gt;i have an statement which i have to correct because it shows the wrong result.&lt;BR /&gt;&lt;BR /&gt;i want to search an excat string in another string, command "grep" shows the wrong result:&lt;BR /&gt;&lt;BR /&gt;example:&lt;BR /&gt;&lt;BR /&gt;STRINGS="string1 string2 string3"&lt;BR /&gt;search_string="string"&lt;BR /&gt;&lt;BR /&gt;incorrect:&lt;BR /&gt;if [ `echo "${STRINGS}" | grep "${search_string}"  &amp;gt; /dev/null 2&amp;gt;/dev/null; \&lt;BR /&gt;                      echo $?` -gt 0 ]&lt;BR /&gt;then&lt;BR /&gt;  echo "not found"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;my solution will be a "for statement":&lt;BR /&gt;exists="N"&lt;BR /&gt;for string in ${STRINGS}&lt;BR /&gt;do&lt;BR /&gt;  if [ "${string}" = "${search_string}" ]&lt;BR /&gt;  then&lt;BR /&gt;    exists="J"&lt;BR /&gt;    break&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;echo $exists&lt;BR /&gt;&lt;BR /&gt;is there any solution with one command. i will use in a shell script, also it possible to use perl for this but my experience in perl is very small ...&lt;BR /&gt;&lt;BR /&gt;regards&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Jun 2008 08:49:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211106#M91717</guid>
      <dc:creator>Billa-User</dc:creator>
      <dc:date>2008-06-05T08:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: search excat string in another string (grep "fails")</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211107#M91718</link>
      <description>hello,&lt;BR /&gt;&lt;BR /&gt;you can use le -w flag for grep:&lt;BR /&gt;#&amp;gt; STRINGS="string1 string2 string3"&lt;BR /&gt;#&amp;gt; search=string&lt;BR /&gt;#&amp;gt; echo "${STRINGS}" |grep -w "$search_string"&lt;BR /&gt;return nothing&lt;BR /&gt;&lt;BR /&gt;#&amp;gt; search=string2&lt;BR /&gt;#&amp;gt; echo "${STRINGS}" |grep -w "$search_string"&lt;BR /&gt;string1 string2 string3&lt;BR /&gt;&lt;BR /&gt;hope it'll help you&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Cerick Gaillard</description>
      <pubDate>Thu, 05 Jun 2008 09:45:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211107#M91718</guid>
      <dc:creator>mobidyc</dc:creator>
      <dc:date>2008-06-05T09:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: search excat string in another string (grep "fails")</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211108#M91719</link>
      <description>&lt;!--!*#--&gt;Using Cerick's suggestion, you can do:&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;STRINGS="string1 string2 string3"&lt;BR /&gt;search_string="string"&lt;BR /&gt;echo "${STRINGS}" | grep -qw "${search_string}"&lt;BR /&gt;if [ $? -ne 0 ]; then&lt;BR /&gt;   echo "not found"&lt;BR /&gt;fi</description>
      <pubDate>Thu, 05 Jun 2008 10:01:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211108#M91719</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-06-05T10:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: search excat string in another string (grep "fails")</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211109#M91720</link>
      <description>thank a lot for the very fast replies, i didn't know option "-w" before this day. it bring the exact result, great.</description>
      <pubDate>Thu, 05 Jun 2008 10:29:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211109#M91720</guid>
      <dc:creator>Billa-User</dc:creator>
      <dc:date>2008-06-05T10:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: search excat string in another string (grep "fails")</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211110#M91721</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Here's a Perl solution embedded in a shell:&lt;BR /&gt;&lt;BR /&gt;# S="In here or there is his or her string"&lt;BR /&gt;# X="her"&lt;BR /&gt;&lt;BR /&gt;# echo ${S} | perl -ne 'BEGIN{$X=shift or die};exit 0 if m{\b$X\b}i;exit 1' $(echo ${X})&lt;BR /&gt;&lt;BR /&gt;# [ $? -eq 0 ] &amp;amp;&amp;amp; echo "ok!" || echo "not found"&lt;BR /&gt;ok!&lt;BR /&gt;&lt;BR /&gt;Notice that the match for the string ${X} in the string ${S} is a case-insensitive match that is bounded (\b) by non-word characters like the '-w' option of 'grep'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Jun 2008 11:17:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211110#M91721</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-05T11:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: search excat string in another string (grep "fails")</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211111#M91722</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;A quick addendum after much needed coffee.  You certainly don't need the trailing $(echo ${X}) !!!  The Perl snippet that emulates 'grep -qw' is simply:&lt;BR /&gt;&lt;BR /&gt;# echo ${S} | perl -ne 'BEGIN{$X=shift or die};exit 0 if m{\b$X\b}i;exit 1' ${X}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 05 Jun 2008 12:12:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211111#M91722</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-05T12:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: search excat string in another string (grep "fails")</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211112#M91723</link>
      <description>&lt;!--!*#--&gt;&amp;gt; [...] command "grep" shows the wrong result:&lt;BR /&gt;&lt;BR /&gt;What (would you say) is the "right" result?&lt;BR /&gt;Would adding some spaces do what you want?&lt;BR /&gt;&lt;BR /&gt;echo " ${STRINGS} " | grep " ${search_string} "</description>
      <pubDate>Thu, 05 Jun 2008 14:05:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211112#M91723</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-06-05T14:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: search excat string in another string (grep "fails")</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211113#M91724</link>
      <description>&amp;gt;Steven: Would adding some spaces do what you want?&lt;BR /&gt;&lt;BR /&gt;Unfortunately this doesn't work at beginning and ending of line or if delimited by punctuation.  -w makes this all a no-brainer.</description>
      <pubDate>Fri, 06 Jun 2008 05:47:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211113#M91724</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-06-06T05:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: search excat string in another string (grep "fails")</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211114#M91725</link>
      <description>&amp;gt; Unfortunately this doesn't work at&lt;BR /&gt;&amp;gt; beginning and ending of line&lt;BR /&gt;&lt;BR /&gt;Look again at where I put those spaces.  It&lt;BR /&gt;sure seemed to work when I tried it.  Did it&lt;BR /&gt;fail for you?  (Demonstrate?)&lt;BR /&gt;&lt;BR /&gt;&amp;gt; or if delimited by punctuation. -w makes&lt;BR /&gt;&amp;gt; this all a no-brainer.&lt;BR /&gt;&lt;BR /&gt;I like whatever works, wherever it works.  I&lt;BR /&gt;may still have an old grep somewhere which&lt;BR /&gt;doesn't do "-w", but I have spaces&lt;BR /&gt;everywhere.</description>
      <pubDate>Fri, 06 Jun 2008 05:57:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211114#M91725</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-06-06T05:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: search excat string in another string (grep "fails")</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211115#M91726</link>
      <description>&amp;gt;Look again at where I put those spaces.&lt;BR /&gt;&lt;BR /&gt;I was looking closer at the grep than the echo.&lt;BR /&gt;But my comment was more geared to files where there is whitespaces vs spaces, punctuation, etc.</description>
      <pubDate>Fri, 06 Jun 2008 06:52:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211115#M91726</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-06-06T06:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: search excat string in another string (grep "fails")</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211116#M91727</link>
      <description>&amp;gt; I was looking closer at the grep than the&lt;BR /&gt;&amp;gt; echo.  [...]&lt;BR /&gt;&lt;BR /&gt;And I was looking more closely at the problem&lt;BR /&gt;posed by the questioner.&lt;BR /&gt;&lt;BR /&gt;As usual, depending on the details, there's&lt;BR /&gt;more than one way to solve a problem like&lt;BR /&gt;this.  Many things are possible.</description>
      <pubDate>Fri, 06 Jun 2008 14:39:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211116#M91727</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-06-06T14:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: search excat string in another string (grep "fails")</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211117#M91728</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Steven: As usual, depending on the details, there's more than one way to solve a problem like this. Many things are possible.&lt;BR /&gt;&lt;BR /&gt;Indeed that is one reason I suggested a Perl solution: TMTOWTDI&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 06 Jun 2008 15:02:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-excat-string-in-another-string-grep-quot-fails-quot/m-p/4211117#M91728</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-06T15:02:22Z</dc:date>
    </item>
  </channel>
</rss>

