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!

Searching loggs

Status
Not open for further replies.

Taiger

Programmer
Nov 22, 2007
4
EU
Okay not a programmer even to it says so above but did not find a newbe tag :)

Hello, I’m making my first small awk program and have a small problem with getting it to work as I want
I’m sorry if this question have been answered before(It probably have) but I tried to search but didn’t know
what to search for. But anyway, My program is connecting to my TCP port on my server and there listening
to log messages, this works quite ok but to get it “bullet proofed” I would need some help. My current program:

awk '$5~/Argument1/ { printf $9 } /Argument2/ {if ($10 == "something") print " Here is something"
if ($10 == "Something else") print " Here is something else"; if ($10 == "Even more stuff") print " Ooh look here" } ’

But to make it safer I would like the program to check that Argument1 and Argument 2 are on the same line
Now it sometimes cheats and read Argument2 from some other line. It is passing a lot of messages in the log and
Argument1 and Argument2 exist on other lines to but I’m only interested in them if they are on the same line.
:) Also the ifs that comes after Argument2 needs to be on the same line as Arbument1 and Argument2

This is probably not impossible, but to me it seams to be have been working on this 2 days now. :(
 
Sorry but the hole program looks like this

nc some.server.bah port |
awk '$5~/Argument1/ { printf $9 } /Argument2/ {if ($10 == "something") print " Here is something"
if ($10 == "Something else") print " Here is something else"; if ($10 == "Even more stuff") print " Ooh look here" } ’
 
Like this ?
awk '/Argument1/ && /Argument2/ {
printf "%s",$9
if ($10 == "something")
...
}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
YES, tanks I have been trying with almost the same ting but have not got it to work,
But I have never had this print “%s”,$9 there before.
What do “%s” mean?

But anyway tanx for a good solution :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top