pattern match #2

  • Follow


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
0
Reply snogfest_hosebeast (252) 10/29/2009 2:09:26 AM

Mebbe:

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

Hope this helps
Casey

On Oct 28, 9:09=A0pm, Henry <snogfest_hosebe...@yahoo.com> wrote:
> 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 =A0 =A0 R
> javax.mail.MessagingException: Unknown SMTP host: mailhost;
> =A0 nested exception is:
> =A0 =A0 =A0 =A0 java.net.UnknownHostException: mailhost

0
Reply caseyjbrotherton 10/30/2009 3:00:36 PM


On Oct 31, 4:00=A0am, "caseyjbrother...@gmail.com"
<caseyjbrother...@gmail.com> wrote:
> Mebbe:
>
> egrep "^[javax.mail.MessagingException|java.net.UnknownHost|nested
> exception is]?exception"
>
> Hope this helps
> Casey
>
> On Oct 28, 9:09=A0pm, Henry <snogfest_hosebe...@yahoo.com> wrote:
>
> > 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 =A0 =A0 R
> > javax.mail.MessagingException: Unknown SMTP host: mailhost;
> > =A0 nested exception is:
> > =A0 =A0 =A0 =A0 java.net.UnknownHostException: mailhost
>
>

no. returns null
0
Reply Henry 10/30/2009 7:37:25 PM

>
> > > 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

0
Reply caseyjbrotherton 11/2/2009 5:03:36 PM

On Nov 3, 6:03=A0am, "caseyjbrother...@gmail.com"
<caseyjbrother...@gmail.com> wrote:
> > > > egrep "[^(javax.mail.MessagingException)+|^(java.net.UnknownHost)+|=
^
> > > > (nested exception is )+]?exception"
>
> Whoops,
> Sorry about that.
>
> So, I think that I made two mistakes:
> 1) =A0made a mistake last time, and read ^ in your regexp as "not"
> instead of "Beginning of line", and transferred that to my thinking.
> =A0 =A0 Not sure where that came from.
>
> 2) =A0I copied your example, and added two lines with "exception"
> before and after, but
> =A0 it worked by coincidence. Some of the exclusions were based on the
> excludes not being at the beginning of the string.
> =A0 The javax.mail exclusion worked because there wasn't also a
> "exception" =A0on the same line (With all lowercase)
>
> It still should have picked up any lines with "exception" =A0though...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. =A0More
> verbose...But (to me) =A0easier 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;} =A0tolower
> ($0)~/exception/'
>
> But looking at the egrep man page, I don't see how to get a "not" =A0out
> 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

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
Reply Henry 11/2/2009 9:46:22 PM

4 Replies
166 Views

(page loaded in 0.158 seconds)

Similiar Articles:













7/26/2012 2:51:22 PM


Reply: