- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: egrep with variable on input
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-09-2009 07:27 AM
тАО09-09-2009 07:27 AM
This is not correct
if [[ $(echo $TNSSTRING | egrep -i (ORA-01|ORA-27) | wc -l) -gt 0 ]]; then
How to use the $TNSSTRING variable as a file for egrep ?
Bests regards
Den
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-09-2009 08:15 AM
тАО09-09-2009 08:15 AM
Re: egrep with variable on input
> file for egrep ?
What does this mean? Does TNSSTRING contain
a file name, or does it contain the data
which you are trying to search?
One line out of a bigger script does not tell
me as much as you might hope that it does.
What does
echo $TNSSTRING
give you?
Where are the data which you are trying to
search?
Better still: What are you trying to do?
It may make more sense to find a better
solution to the actual problem than it does
to try to fix some sub-ideal scheme. But,
because my psychic powers are so weak, this
would require you to describe the actual
problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-09-2009 08:24 AM
тАО09-09-2009 08:24 AM
Re: egrep with variable on input
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
-0751: Unable to connect to Oracle. Exiting SQL*Plus
The errors come because we have a ( character in the input data ...
oas_check_sqlnet.ksh[81]: 0403-057 Syntax error at line 1 : `(' is not expected.
Bests Regards
Den
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-09-2009 08:25 AM
тАО09-09-2009 08:25 AM
Re: egrep with variable on input
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-09-2009 03:23 PM
тАО09-09-2009 03:23 PM
Re: egrep with variable on input
egrep -i 'ORA-01|ORA-27'
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.
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 && operators to handle the various cases.
For example:
--
$ t="this is a string"
$ echo $t | egrep -iq 'STRING'
$ echo $?
0
$ echo $t | egrep -iq 'STRONG'
$ echo $?
1
$ echo $t | egrep -iq 'STRING' && echo Match
Match
$ echo $t | egrep -iq 'STRONG' || echo No match
No match
--
Any POSIX shell should handle this, such as ksh and bash.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2009 04:04 AM
тАО09-10-2009 04:04 AM
Re: egrep with variable on input
The problem is not with egrep -i (ORA-01|ORA-27)
BUT
With "(" inside variables ;-)
Try your example with t="this is () a problem" and this will break your idea.
!!!
Bests Regards
Den
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2009 05:12 AM
тАО09-10-2009 05:12 AM
Re: egrep with variable on input
Perhaps you could provide some simple test
case which would show us exactly what you
think this problem is. I know of no
particular shell problem with "(" (or ")")
in a variable's value. For example:
bash$ t='abc
> a(b)c
> xyz'
bash$ echo "$t"
abc
a(b)c
xyz
bash$ echo "$t" | grep b
abc
a(b)c
I see what I expect.
You may have a problem somewhere in your
(complex) procedure which does some Oracle
magic, but I don't think that you know what
the problem is, or where it is. And it's
easier to see these things when you look at
smaller bits.
> The errors come because [...]
Who is complaining? What did he see? Who
sent him that stuff?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2009 05:31 AM
тАО09-10-2009 05:31 AM
Re: egrep with variable on input
Quote your variables and replace the un-escaped parens in the egrep statement.
--
$ t="()()()()()()(())((()))"
$ echo $"t" | egrep -i (nope|nothere)
bash: syntax error near unexpected token `('
$ echo $"t" | egrep -i 'nope|nothere'
$ echo "$t" | egrep -i 'nope|()'
()()()()()()(())((()))
--
The shell is trying to interpret the parens before it even tries to run the egrep command. It's not the variable contents.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2009 06:34 AM
тАО09-10-2009 06:34 AM
Re: egrep with variable on input
(ORA-01|ORA-27) expression contains '|' wich is piping character. So when the shell interpret this string the ( char is not balanced!
I don't understand the () !
If you try to use | as or bitwise operator between two strings your syntax needs to be egrep -i "ORA-01|ORA-27"
Regards,
Roland
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2009 04:06 PM
тАО09-10-2009 04:06 PM
SolutionYou 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'.
This works (for example):
# TNSSTRING="curly {} stuff"
# [[ $(echo $TNSSTRING | egrep -i "(ORA-01|ORA-27|\{\}|())" | wc -l) -gt 0 ]] && echo OK
...as does this:
# TNSSTRING="this is () NOT a problem"
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.
With Perl, you could slurp (read-up a whole file into memory) and do things like:
# TNSSTRING="Leo\nthe\ncat"
# echo ${TNSSTRING}
Leo
the
cat
# echo $TNSSTRING | perl -00 -nle 'print "MATCHED" if m{Leo\nthe\ncat}'
MATCHED
LASTLY:
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:
http://forums.itrc.hp.com/service/forums/helptips.do?#28
Please review your previous posts with unevaluated replies:
http://forums.itrc.hp.com/service/forums/pageList.do?userId=BR967434&listType=unassigned&forumId=1
The time _YOU_ take will be ample reward for the time _WE_ take to help you. Thanks.
Regards!
...JRF...