1834177 Members
2368 Online
110064 Solutions
New Discussion

A grep Question

 
SOLVED
Go to solution
GerGon
Regular Advisor

A grep Question

Hi ...

I get listener.ora file, I need to extract, only connections done by sql or sqlnav, but no include user like xx,yyy,zz,mmm,etc..

I wrote in HP-UX v11:
cat listener.log | grep -v "hbeans|lsmith" > a1
or
cat listener.log | grep -i sjones -v 'hbeans|lsmith' > a1

But, it does not work, a1 file have nothing.. I probe with single qoute and nothing too.

Any idea...
Thanks...
6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: A grep Question

try

cat listener.log | grep -v hbeans | grep -v lsmith > a1

Should work

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Sundar_7
Honored Contributor
Solution

Re: A grep Question

hbeans|lsmith is an extended regular expression that grep will not support.

use egrep

cat listener.log | egrep -i "hbeans|lsmith" >> a1
Learn What to do ,How to do and more importantly When to do ?
Sundar_7
Honored Contributor

Re: A grep Question

To use Extended Regular expressions with grep, you need to use -E/-e options.
Learn What to do ,How to do and more importantly When to do ?
john korterman
Honored Contributor

Re: A grep Question

Hi,

and it would work faster without cat, e.g.:
# grep -Eiv "hbean|smith|jones" listener.log >a1

regards,
John K.
it would be nice if you always got a second chance
John Kittel
Trusted Contributor

Re: A grep Question

You can also use multiple -e arguments with -v, so this works as well:

cat listener.log | grep -v -e "hbeans" -e "lsmith" > a1

And, BTW, not exactly related to your question, but interesting and useful nonetheless...

It is a rather classic misuse or inefficiency to start pipelines with cat in this way. grep takes an input file argument. So something like this for exmple:

cat listener.log | grep -v -e "hbeans" -e "lsmith" > a1

is better written as this:

grep -v -e "hbeans" -e "lsmith" listener.log > a1



GerGon
Regular Advisor

Re: A grep Question

Thanks a lot to all..