Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pattern match

7 views
Skip to first unread message

Henry

unread,
Oct 28, 2009, 10:09:26 PM10/28/09
to
I'm trying an include/exclude list in 1 hit for a wrapper script
I want to get a hit on the string "exception" but exclude all the
other java bit's that are ok

egrep "[^(javax.mail.MessagingException)+|^(java.net.UnknownHost)+|^
(nested exception is )+]?exception"

kind of works; but not excluding this pattern:
nested exception is:

I'm basically trying to exclude all of this, but catch lines with
"exception"

[17/10/09 18:30:16:524 NZDT] 0000005b SystemErr R
javax.mail.MessagingException: Unknown SMTP host: mailhost;
nested exception is:
java.net.UnknownHostException: mailhost

caseyjbr...@gmail.com

unread,
Oct 30, 2009, 11:00:36 AM10/30/09
to

Mebbe:

egrep "^[javax.mail.MessagingException|java.net.UnknownHost|nested
exception is]?exception"

Hope this helps
Casey

Henry

unread,
Oct 30, 2009, 3:37:25 PM10/30/09
to
On Oct 31, 4:00 am, "caseyjbrother...@gmail.com"

no. returns null

caseyjbr...@gmail.com

unread,
Nov 2, 2009, 12:03:36 PM11/2/09
to

>
> > > egrep "[^(javax.mail.MessagingException)+|^(java.net.UnknownHost)+|^
> > > (nested exception is )+]?exception"
>

Whoops,
Sorry about that.

So, I think that I made two mistakes:
1) made a mistake last time, and read ^ in your regexp as "not"
instead of "Beginning of line", and transferred that to my thinking.
Not sure where that came from.

2) I copied your example, and added two lines with "exception"
before and after, but
it worked by coincidence. Some of the exclusions were based on the
excludes not being at the beginning of the string.
The javax.mail exclusion worked because there wasn't also a
"exception" on the same line (With all lowercase)


It still should have picked up any lines with "exception" though...So
I assume that maybe you want a mixed case exception to be printed?

I would normally cheat with something like this, and use perl. More
verbose...But (to me) easier to read.
(Everything below should be for mixed case "exception"

cat ~/junk | perl -ne '/exception/i and do{ /
javax.mail.MessagingException/ and next;
/java.net.UnknownHost/ and next;
/nested exception is/ and next;
print $_;
}'


Or awk:
cat ~/junk | awk '/java.net.UnknownHost/||/
javax.mail.MessagingException/||/nested exception is/{next;} tolower
($0)~/exception/'

But looking at the egrep man page, I don't see how to get a "not" out
of egrep, except this two stage approach:

cat ~/junk | grep -i exception | egrep -v 'java.net.UnknownHost|
javax.mail.MessagingException|nested exception is'


Hope that actually helps.
Casey

Henry

unread,
Nov 2, 2009, 4:46:22 PM11/2/09
to
On Nov 3, 6:03 am, "caseyjbrother...@gmail.com"

thanks Casey, I was trying to use a standard Nagios plug-in called
check_log which uses grep.
I have switched to a hand-written awk script :)

0 new messages