grepping a log file
Hello
I have an assp log file which contains spam score data for each log line like this Apr-3-07 03:32:31 PB: 205.158.154.152 score: 0+15 => 15 reason:205.158.154.152:RelayAttempt I would grep/sed only those messages which have score > 20 , for example Apr-3-07 03:32:31 PB: 205.158.154.152 score: 30+15 => 45 reason:205.158.154.152:RelayAttempt should be showed. how to do that please ? Thanks ! |
hi there! awk should solve your problem. I'm not really good at it but I've tried the code below and it worked. There maybe other solution nicer than this one..
Code:
awk '{if ($8 > 20) print $1,$2,$3,$4,$5,$6,$7,$8,$9}' logfile |
Quote:
f a n t a s t i c , thanks! |
Quote:
Code:
awk '{if ($8 > 20) print $0}' logfile |
Quote:
Cheers! |
more difficult
suppose I have to accept the result only if the line before had "domain.com" in it I tried Code:
awk '{if ($8 > 1 && grep -B1 "domain.com"!="" ) print $0}' |
I had something similar come up the other day, this is how I did it:
Code:
awk '/domain\.com/ {print $0}' edit 2: that'll teach me for not reading your post correctly! You wanted it only if the line before it also contained domain.com. Sorry, my mistake! I think sed might be your friend here. |
Quote:
for example Apr-4-07 05:13:29 88.227.8.201 <murbrianmorrowhat@brianmorrow.com> recipient delayed: mrodriguez@domain.com Apr-4-07 05:13:39 PB: 88.227.8.201 score: 0+150 => 150 reason:LimitingIPFrequency Apr-4-07 05:13:39 PB: 88.227.8.201 score: 0+150 => 150 reason:LimitingIPFrequency should be showed/returned because the line before contains domain.com on this other case Apr-4-07 05:13:29 88.227.8.201 <murbrianmorrowhat@brianmorrow.com> recipient delayed: mrodriguez@yahoo.com Apr-4-07 05:13:39 PB: 88.227.8.201 score: 0+150 => 150 reason:LimitingIPFrequency the command should return nothing because domain.com is not on the line before. Thanks |
Haven't tried this, but maybe this'll inspire you...
Code:
awk 'BEGIN {printNext=0;} {if ($8 > 20) print $0; printNext=0} /domain\.com/ {printNext=1;} {printNext=0}/' logfile to run the awk commands from that file. I'm not entirely sure of the syntax either. You may need to put a $ before printNext, for instance. |
I'm no expert, but here's what I'd try ...
grep -A1 logfile domain.com | awk '{if ($8 > 20) print $0}' Would that work? |
greping log
awk '/domain\.com/ {print $0}'
|
Quote:
Code:
awk '{if($8 > 1) {if(hold ~ "domain.com") {print $0)}} hold=$0}' filename Code:
awk '{ |
All times are GMT -5. The time now is 04:31 PM. |