Nik_stack Nik_stack - 4 years ago 253
Bash Question

GREP search modification: filter by string

I have following grep command which looks for 'Exception in' string in the logs for past 24 hours via remote machine and prints out next 40 lines.

ssh $host $'sed -e "1,/^$(date -d -20hour +\'%Y-%m-%d %H\')/d" /mylogs.out | grep -A40 "Exception in"' >> $log

This works well to catch Exceptions such as below:

2016-02-08 13:19:34,034 ERROR [qtp859655531-3974] com.project.actions.CustomStatsAction - Exception in .....

However, sometimes, the line starts with WARN instead of ERROR and I dont want lines with WARN in my result. Example:

2016-02-08 13:19:34,034 WARN [qtp859655531-3974] com.project.actions.CustomStatsAction - Exception in ....

How should I modify my query to achieve this?

Answer Source

Use grep -A40 -E "ERROR .*Exception in"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download