<?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: egrep with variable on input in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198234#M51207</link>
    <description>I would remove the parens around the egrep pattern. Try writing it as:&lt;BR /&gt;egrep -i 'ORA-01|ORA-27'&lt;BR /&gt;&lt;BR /&gt;You'll probably also want to put double-quotes around "$TNSSTRING" when you use it, since there's a line break and spaces in it - never assume your input will look the same every time.&lt;BR /&gt;&lt;BR /&gt;Another thing, is instead of invoking "wc" to count, try using the "-q" option to egrep, then check the return code with the "$?" variable or using || and/or &amp;amp;&amp;amp; operators to handle the various cases. &lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;--&lt;BR /&gt;$ t="this is a string"&lt;BR /&gt;$ echo $t | egrep -iq 'STRING' &lt;BR /&gt;$ echo $?&lt;BR /&gt;0&lt;BR /&gt;$ echo $t | egrep -iq 'STRONG' &lt;BR /&gt;$ echo $?&lt;BR /&gt;1&lt;BR /&gt;$ echo $t | egrep -iq 'STRING' &amp;amp;&amp;amp; echo Match&lt;BR /&gt;Match&lt;BR /&gt;$ echo $t | egrep -iq 'STRONG' || echo No match&lt;BR /&gt;No match&lt;BR /&gt;--&lt;BR /&gt;&lt;BR /&gt;Any POSIX shell should handle this, such as ksh and bash.</description>
    <pubDate>Wed, 09 Sep 2009 22:23:42 GMT</pubDate>
    <dc:creator>macosta</dc:creator>
    <dc:date>2009-09-09T22:23:42Z</dc:date>
    <item>
      <title>egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198230#M51203</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;This is not correct&lt;BR /&gt; if [[  $(echo $TNSSTRING | egrep -i (ORA-01|ORA-27) | wc -l) -gt 0 ]]; then &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;How to use the $TNSSTRING variable as a file for egrep ?&lt;BR /&gt;&lt;BR /&gt;Bests regards&lt;BR /&gt;Den</description>
      <pubDate>Wed, 09 Sep 2009 14:27:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198230#M51203</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-09-09T14:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198231#M51204</link>
      <description>&lt;!--!*#--&gt;&amp;gt; How to use the $TNSSTRING variable as a&lt;BR /&gt;&amp;gt; file for egrep ?&lt;BR /&gt;&lt;BR /&gt;What does this mean?  Does TNSSTRING contain&lt;BR /&gt;a file name, or does it contain the data&lt;BR /&gt;which you are trying to search?&lt;BR /&gt;&lt;BR /&gt;One line out of a bigger script does not tell&lt;BR /&gt;me as much as you might hope that it does.&lt;BR /&gt;&lt;BR /&gt;What does&lt;BR /&gt;      echo $TNSSTRING&lt;BR /&gt;give you?&lt;BR /&gt;&lt;BR /&gt;Where are the data which you are trying to&lt;BR /&gt;search?&lt;BR /&gt;&lt;BR /&gt;Better still: What are you trying to do?&lt;BR /&gt;&lt;BR /&gt;It may make more sense to find a better&lt;BR /&gt;solution to the actual problem than it does&lt;BR /&gt;to try to fix some sub-ideal scheme.  But,&lt;BR /&gt;because my psychic powers are so weak, this&lt;BR /&gt;would require you to describe the actual&lt;BR /&gt;problem.</description>
      <pubDate>Wed, 09 Sep 2009 15:15:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198231#M51204</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-09-09T15:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198232#M51205</link>
      <description>$TNSSTRING contains more than one lines !&lt;BR /&gt;&lt;BR /&gt;Here an Example of result with $TNSSTRING = SQL*Plus: Release 10.2.0.1.0 - Production on Wed Sep 9 11:24:10 2009 Copyright (c) 1982, 2005, Oracle. All rights reserved. ERROR: ORA-12154: TNS:could not resolve the connect identifier specified SP2&lt;BR /&gt;-0751: Unable to connect to Oracle. Exiting SQL*Plus&lt;BR /&gt;&lt;BR /&gt;The errors come because we have a ( character in the input data ...&lt;BR /&gt;&lt;BR /&gt;oas_check_sqlnet.ksh[81]: 0403-057 Syntax error at line 1 : `(' is not expected.&lt;BR /&gt;&lt;BR /&gt;Bests Regards&lt;BR /&gt;Den&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Sep 2009 15:24:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198232#M51205</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-09-09T15:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198233#M51206</link>
      <description>Of course I could create a file first in /tmp and use it as input after but it's not very nice !&lt;BR /&gt;...</description>
      <pubDate>Wed, 09 Sep 2009 15:25:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198233#M51206</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-09-09T15:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198234#M51207</link>
      <description>I would remove the parens around the egrep pattern. Try writing it as:&lt;BR /&gt;egrep -i 'ORA-01|ORA-27'&lt;BR /&gt;&lt;BR /&gt;You'll probably also want to put double-quotes around "$TNSSTRING" when you use it, since there's a line break and spaces in it - never assume your input will look the same every time.&lt;BR /&gt;&lt;BR /&gt;Another thing, is instead of invoking "wc" to count, try using the "-q" option to egrep, then check the return code with the "$?" variable or using || and/or &amp;amp;&amp;amp; operators to handle the various cases. &lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;--&lt;BR /&gt;$ t="this is a string"&lt;BR /&gt;$ echo $t | egrep -iq 'STRING' &lt;BR /&gt;$ echo $?&lt;BR /&gt;0&lt;BR /&gt;$ echo $t | egrep -iq 'STRONG' &lt;BR /&gt;$ echo $?&lt;BR /&gt;1&lt;BR /&gt;$ echo $t | egrep -iq 'STRING' &amp;amp;&amp;amp; echo Match&lt;BR /&gt;Match&lt;BR /&gt;$ echo $t | egrep -iq 'STRONG' || echo No match&lt;BR /&gt;No match&lt;BR /&gt;--&lt;BR /&gt;&lt;BR /&gt;Any POSIX shell should handle this, such as ksh and bash.</description>
      <pubDate>Wed, 09 Sep 2009 22:23:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198234#M51207</guid>
      <dc:creator>macosta</dc:creator>
      <dc:date>2009-09-09T22:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198235#M51208</link>
      <description>Hi Macosta&lt;BR /&gt;&lt;BR /&gt;The problem is not with egrep -i (ORA-01|ORA-27) &lt;BR /&gt;&lt;BR /&gt;BUT&lt;BR /&gt;&lt;BR /&gt;With "(" inside variables ;-)&lt;BR /&gt;&lt;BR /&gt;Try your example with t="this is () a problem" and this will break your idea. &lt;BR /&gt;&lt;BR /&gt;!!!&lt;BR /&gt;&lt;BR /&gt;Bests Regards&lt;BR /&gt;Den&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Sep 2009 11:04:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198235#M51208</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-09-10T11:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198236#M51209</link>
      <description>&lt;!--!*#--&gt;&amp;gt; With "(" inside variables ;-)&lt;BR /&gt;&lt;BR /&gt;Perhaps you could provide some simple test&lt;BR /&gt;case which would show us exactly what you&lt;BR /&gt;think this problem is.  I know of no&lt;BR /&gt;particular shell problem with "(" (or ")")&lt;BR /&gt;in a variable's value.  For example:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;bash$ t='abc&lt;BR /&gt;&amp;gt; a(b)c&lt;BR /&gt;&amp;gt; xyz'&lt;BR /&gt;bash$ echo "$t"&lt;BR /&gt;abc&lt;BR /&gt;a(b)c&lt;BR /&gt;xyz&lt;BR /&gt;bash$ echo "$t" | grep b&lt;BR /&gt;abc&lt;BR /&gt;a(b)c&lt;BR /&gt;&lt;BR /&gt;I see what I expect.&lt;BR /&gt;&lt;BR /&gt;You may have a problem somewhere in your&lt;BR /&gt;(complex) procedure which does some Oracle&lt;BR /&gt;magic, but I don't think that you know what&lt;BR /&gt;the problem is, or where it is.  And it's&lt;BR /&gt;easier to see these things when you look at&lt;BR /&gt;smaller bits.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The errors come because [...]&lt;BR /&gt;&lt;BR /&gt;Who is complaining?  What did he see?  Who&lt;BR /&gt;sent him that stuff?</description>
      <pubDate>Thu, 10 Sep 2009 12:12:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198236#M51209</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-09-10T12:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198237#M51210</link>
      <description>Leo, please at try my suggestions before disagreeing with them. If you had done so, we'd be done here.&lt;BR /&gt;&lt;BR /&gt;Quote your variables and replace the un-escaped parens in the egrep statement.&lt;BR /&gt;&lt;BR /&gt;--&lt;BR /&gt;$ t="()()()()()()(())((()))"&lt;BR /&gt;$ echo $"t" | egrep -i (nope|nothere)&lt;BR /&gt;bash: syntax error near unexpected token `('&lt;BR /&gt;$ echo $"t" | egrep -i 'nope|nothere'&lt;BR /&gt;$ echo "$t" | egrep -i 'nope|()'&lt;BR /&gt;()()()()()()(())((()))&lt;BR /&gt;--&lt;BR /&gt;&lt;BR /&gt;The shell is trying to interpret the parens before it even tries to run the egrep command. It's not the variable contents.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Sep 2009 12:31:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198237#M51210</guid>
      <dc:creator>macosta</dc:creator>
      <dc:date>2009-09-10T12:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198238#M51211</link>
      <description>Hello&lt;BR /&gt;&lt;BR /&gt;(ORA-01|ORA-27) expression contains '|' wich is piping character. So when the shell interpret this string the ( char is not balanced!&lt;BR /&gt;&lt;BR /&gt;I don't understand the () !&lt;BR /&gt;If you try to use | as or bitwise operator between two strings your syntax needs to be egrep -i "ORA-01|ORA-27"&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Roland</description>
      <pubDate>Thu, 10 Sep 2009 13:34:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198238#M51211</guid>
      <dc:creator>Roland Piette</dc:creator>
      <dc:date>2009-09-10T13:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198239#M51212</link>
      <description>Hi Den:&lt;BR /&gt;&lt;BR /&gt;You need to double quote the extended regular expression so that the shell doesn't interpret the special characters but lets them pass along to 'grep'.&lt;BR /&gt;&lt;BR /&gt;This works (for example):&lt;BR /&gt;&lt;BR /&gt;# TNSSTRING="curly {} stuff"&lt;BR /&gt;# [[ $(echo $TNSSTRING | egrep -i "(ORA-01|ORA-27|\{\}|())" | wc -l) -gt 0 ]] &amp;amp;&amp;amp; echo OK&lt;BR /&gt;&lt;BR /&gt;...as does this:&lt;BR /&gt;&lt;BR /&gt;# TNSSTRING="this is () NOT a problem"&lt;BR /&gt;&lt;BR /&gt;NOW, you mentioned that your TNSSTRING Variable actually consisted of multiple lines.  Filters like 'grep' are not going to help here since they are line-oriented.&lt;BR /&gt;&lt;BR /&gt;With Perl, you could slurp (read-up a whole file into memory) and do things like:&lt;BR /&gt;&lt;BR /&gt;# TNSSTRING="Leo\nthe\ncat"&lt;BR /&gt;# echo ${TNSSTRING}&lt;BR /&gt;Leo&lt;BR /&gt;the&lt;BR /&gt;cat&lt;BR /&gt;&lt;BR /&gt;# echo $TNSSTRING | perl -00 -nle 'print "MATCHED" if m{Leo\nthe\ncat}'&lt;BR /&gt;MATCHED&lt;BR /&gt;&lt;BR /&gt;LASTLY:&lt;BR /&gt;&lt;BR /&gt;While you ask interesting questions, you sometimes fail to come back to assign points to answers that have been offered.   Points are not only a way of saying "thanks!" but bread-crumbs for future trollers to find the tastiest (most applicable) solution:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/service/forums/helptips.do?#28" target="_blank"&gt;http://forums.itrc.hp.com/service/forums/helptips.do?#28&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;Please review your previous posts with unevaluated replies:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/service/forums/pageList.do?userId=BR967434&amp;amp;listType=unassigned&amp;amp;forumId=1" target="_blank"&gt;http://forums.itrc.hp.com/service/forums/pageList.do?userId=BR967434&amp;amp;listType=unassigned&amp;amp;forumId=1&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;The time _YOU_ take will be ample reward for the time _WE_ take to help you.  Thanks.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Sep 2009 23:06:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198239#M51212</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-09-10T23:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198240#M51213</link>
      <description>&amp;gt;if [[ $(echo $TNSSTRING | egrep -i (ORA-01|ORA-27) | wc -l) -gt 0 ]]; then&lt;BR /&gt;&lt;BR /&gt;As JRF says, it doesn't like your naked ERE.  Any reason you need to use the egrep hammer instead of grep?&lt;BR /&gt;echo "$TNSSTRING" | grep -q -i -e ORA-01 -e ORA-27&lt;BR /&gt;if [[ $? -eq 0 ]]; then</description>
      <pubDate>Sun, 13 Sep 2009 04:18:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198240#M51213</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-09-13T04:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198241#M51214</link>
      <description>Hi Guys&lt;BR /&gt;&lt;BR /&gt;Thank you very much for you answering, I need to study all this staff.&lt;BR /&gt;&lt;BR /&gt;James ! Hey ;-) look my old posts and you'll see that I put very often points. The problen during some times is that I have no time also for  studying your posts (sic) and I don't want to put 10 every times or 9 or 8 or 2 without reflexion !&lt;BR /&gt;&lt;BR /&gt;If all is good I hope to solve this egrep problem tomorrow and of course I'll come back here for closing thread anf submit points. I play the game every time this is possible ans it's not always easy. &lt;BR /&gt;&lt;BR /&gt;See you Guys&lt;BR /&gt;and ... see you later&lt;BR /&gt;Bye</description>
      <pubDate>Mon, 14 Sep 2009 18:04:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198241#M51214</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-09-14T18:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198242#M51215</link>
      <description>Hi Den:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; James ! Hey ;-) look my old posts and you'll see that I put very often points.&lt;BR /&gt;&lt;BR /&gt;I don't disagree and that wasn't my point.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The problen during some times is that I have no time also for studying your posts (sic) and I don't want to put 10 every times or 9 or 8 or 2 without reflexion !&lt;BR /&gt;&lt;BR /&gt;I'll take that remark as a compliment :-)&lt;BR /&gt;&lt;BR /&gt;I agree that knee-jerk point assignment is wrong and meaningless.  However, a little quid pro quo (reflection, if you will) is quite appropriate in my opinion.  If you feel that a post doesn't need or deserve further analysis/commentary, then please consider marking it 'closed'.  You can always reopen it at a later date!&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 14 Sep 2009 18:21:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198242#M51215</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-09-14T18:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198243#M51216</link>
      <description>;-) &lt;BR /&gt;&lt;BR /&gt;Have a nice day James.&lt;BR /&gt;Sure I'll be back here !&lt;BR /&gt;&lt;BR /&gt;Bests Regards&lt;BR /&gt;Den</description>
      <pubDate>Tue, 15 Sep 2009 11:21:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198243#M51216</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-09-15T11:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: egrep with variable on input</title>
      <link>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198244#M51217</link>
      <description>I have no real solution without use a temporary files.&lt;BR /&gt;&lt;BR /&gt;Thanks to you Guys.</description>
      <pubDate>Tue, 15 Sep 2009 12:39:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/egrep-with-variable-on-input/m-p/5198244#M51217</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-09-15T12:39:32Z</dc:date>
    </item>
  </channel>
</rss>

