Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ignoring some found searches 3

Status
Not open for further replies.

Einstein47

Programmer
Nov 29, 2001
737
US
Hey all,

Is there a way with AWK to do like you can with GREP grep "string1" | grep -v "string2"?

I am currently looking for the word Exception in a stderr.log, and this is working good. However, I want to exclude all the Exception lines that also have Login Failed.

This is my current implementation:
Code:
/xception/ {
 print title $0
 title = ""
 fatal++
}
This is identifying all Failed Logins as fatal errors. Any help would be appreciated. Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Wouldn't this accomplish what you are trying to do?

if ($0 ~ /xception/ && $0 !~ /Login failed/) {
actions..
}


 
That did it - Sometimes you can't see the forest for the trees.

Thanks for the quick help, marsd! Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
BEGIN {

}

(tolower($0) ~ "exception") && (tolower($0) ~ "login failed") { next}
{ print }


vlad
 
marsd,

your logic fails for the following sample - skipping the first line:

foo bar
aslkdjhf asldkjhflaskjd laksjdhf Exception
Exception asdklhjf askdjhf askdjhf Login failed 1 2 3
Login Exception foo
Exception
 
I can see your point about case - but that isn't a problem in this case (pun intended)

[yoda] <= he rocked in Ep.II Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
The 'case' is NOT the problem. The problem are lines containing NEITHER of the patterns - marsd's solution skips them.

vlad
 
Hi Vlad,
Thanks for pointing this out, but the OP
was seemingly asking for a simple pattern match
against lines with one pattern but not the other
and made no mention for the inclusion of any other
line. Also you will notice that I just suggested a
skeletal regexp example and did not present the
code as a complete solution.
Lastly, the OP seemed satisfied with this little hint,
rather than a lecture, which is sometimes all you need.
:)

Bye.
 
Howdy,

sorry, didn't mean to be harsh or anything - just offering an alternative solution

vlad
 
The truth is that I have a much larger structure of RE's that I am checking. The &quot;xception&quot; was just one of them. If you really must know, here is my full AWK script. The solution fit nicely where I needed it. All the other cases have been unaffected:
Code:
BEGIN {
  title = &quot;WAS stderr.log:\n&quot;
  flag = 0
  fatal = 0
  warn = 0
}
/Serious system error/ {
  print title &quot; - &quot; $0
  title = &quot;&quot;
  fatal++; flag=1
}
$0 ~ /xception/ && $0 !~ /Login Failed/ {
  print title &quot; - &quot; $0
  title = &quot;&quot;
  fatal++; flag=1
}
$6 ~ /^X$/ {
  print title $0
  title = &quot;&quot;
  fatal++; flag=1;
}
$6 ~ /^W$/ && $0 !~ /using generic settings/ {
  print title $0
  title = &quot;&quot;
  warn++; flag=1;
}
END {
  if (flag > 0) {
    if (fatal > 0) {
      print &quot;----  fatal: &quot; fatal
    }
    if (warn > 0) {
      print &quot;----   warn: &quot; warn
    }
    print
  }
}

Thanks again - and I appreciate all the comments. I know that I was a little terse in my explination of the problem. Sometimes you need the full code and sample input, but sometimes you don't. Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Vlad,
No big deal, it was a just criticism in some CASES.


einstein47,
Yeah, that's how some of my log checking scripts look too..
Great minds and all that...

That's TWO bad puns in one post,I should get an
award.
MD
 
Don't push it marsd [medal] Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
/images/star.gif This is for you vlad. I can see you gunning for tip-master of the week award. /images/star.gif

Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
and this one is for a good sense of humor.

thanks

vlad

[hope this trend won't get too recursive]

 
Just wait until an admin sees this thread - we may all loose our stars. Abusing the system and all. But for what it is worth - getting an answer to a problem that I've been beating my brain against is more than enough reward. (in most cases)

[yoda] vs [smurf] on the next Fox Celebrity Boxing III Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Did I hear the word 'cases'?

That's REALLY recursive.... I should get an award for being perceptive ;)

c ya

vlad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top