I want to
tail -f my logs. However, I want to filter out everything that has the words:
"ELB", "Pingdom", "Health"
I don't know about using awk instead of grep, but this works for me:
EDIT: As dmourati and Caleb pointed out, you could also use
Since they are synonymous commands, it comes down to preference unless you don't have egrep at all. However for forward compatibility it is recommended to use the
Try piping it to egrep with a pipe separated lists of words you want to filter out:
Note that using parenthesis around the list of matches is optional. Since the
For extra credit, it's worth mentioning that
You could also use it to color or otherwise highlight the output instead of just filtering it.
EDit: See DTests answer and the comments for the full explanation of how egrep is just a deprecated alternate way to fire off
Why do you want to log this information?
If you want to have scripted behavior depending on the content of the log files, you may wish to do your filtering using Expect. ( http://en.wikipedia.org/wiki/Expect ) Expect is a Tcl extension but There is also a Python version of Expect.
Expect gives you this powerful flexible switch like statement that lets you specify different behaviors conditionally depending on the states, or patterns present in your input stream. For example:
So you specify patterns in the expect statement, and you specify different behaviors, and you can wrap the whole thing in a loop, and you can easily write very powerful filters that also write portions of your input to different files, or drop it altogether, or take actions and run other scripts depending on what is in your input.
So, it comes down to why are you trying to filter your log files, to take action on log input, or just for archival reasons?