我需要grep error.log文件以获取*ERROR*
和Caused by:
下一行中相同的错误标记
例如:我有error.log,如下所示
08.02.2016 00:11:21.541 *ERROR* [158.151.84.34 [1454908281309] GET /content/user/home/people-search.html HTTP/1.1] com.day.cq.wcm.tags.IncludeTag Error while executing script content.jsp
org.apache.sling.api.scripting.ScriptEvaluationException:
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:388)
at org.apache.sling.scripting.jsp.taglib.IncludeTagHandler.dispatch(IncludeTagHandler.java:59)
at org.apache.sling.scripting.jsp.taglib.AbstractDispatcherTagHandler.doEndTag(AbstractDispatcherTagHandler.java:129)
at org.apache.jsp.libs.foundation.components.parsys.parsys_jsp._jspService(parsys_jsp.java:318)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502)
... 180 common frames omitted
Caused by: org.apache.sling.api.SlingException: javax.servlet.ServletException: java.lang.Exception: user person search is not available
08.02.2016 05:28:56.748 *ERROR* [158.151.84.34 [1454927336516] GET /content/user/home/people-search.html HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught SlingException
org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502)
... 20 common frames omitted
Caused by: java.lang.Exception: user person search is not available
08.02.2016 06:11:24.725 *ERROR* [158.151.84.34 [1454908281309] GET /content/user/home/people-search.html HTTP/1.1] com.day.cq.wcm.tags.IncludeTag Error while executing script content.jsp
org.apache.sling.api.scripting.ScriptEvaluationException:
at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:388)
... 10 common frames omitted
Caused by: org.apache.sling.api.SlingException: javax.servlet.ServletException: java.lang.Exception: user person search is not available
我需要输出
08.02.2016 00:11:21.541 *ERROR* [158.151.84.34 [1454908281309] GET /content/user/home/people-search.html HTTP/1.1] com.day.cq.wcm.tags.IncludeTag Error while executing script content.jsp
Caused by: org.apache.sling.api.SlingException: javax.servlet.ServletException: java.lang.Exception: user person search is not available
08.02.2016 05:28:56.748 *ERROR* [158.151.84.34 [1454927336516] GET /content/user/home/people-search.html HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught SlingException
Caused by: java.lang.Exception: user person search is not available
08.02.2016 06:11:24.725 *ERROR* [158.151.84.34 [1454908281309] GET /content/user/home/people-search.html HTTP/1.1] com.day.cq.wcm.tags.IncludeTag Error while executing script content.jsp
Caused by: org.apache.sling.api.SlingException: javax.servlet.ServletException: java.lang.Exception: user person search is not available
我将如何得到这个?
答案 0 :(得分:3)
egrep '\*ERROR\*|Caused by:' error.log
答案 1 :(得分:1)
怎么样:
grep -e "\*ERROR\*" -e "Caused by:" error.log
答案 2 :(得分:1)
你有没有"引起:"没有" ERROR"线?例如,你能得到一个"警告" (或类似的)后跟一个"引起的"?一个" ERROR"那不是"引起的:"?线路的其他部分中的文本比您的目标位置(ERROR的第3个字段,引起的行的起点)怎么样?如果发生任何此类情况,请编辑您的问题,以便在样本输入/输出中包含这些情况。
这是您在上述所有问题中需要保护的:
$ cat tst.awk
/^[0-9]/ {
if (inErr) {
print "No cause found"
}
if ($3 == "*ERROR*") {
print
inErr = 1
}
}
inErr && /^Caused by:/ {
print
inErr = 0
}
END {
if (inErr) {
print "No cause found"
}
}
$ awk -f tst.awk file
08.02.2016 00:11:21.541 *ERROR* [158.151.84.34 [1454908281309] GET /content/user/home/people-search.html HTTP/1.1] com.day.cq.wcm.tags.IncludeTag Error while executing script content.jsp
Caused by: org.apache.sling.api.SlingException: javax.servlet.ServletException: java.lang.Exception: user person search is not available
08.02.2016 05:28:56.748 *ERROR* [158.151.84.34 [1454927336516] GET /content/user/home/people-search.html HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught SlingException
Caused by: java.lang.Exception: user person search is not available
08.02.2016 06:11:24.725 *ERROR* [158.151.84.34 [1454908281309] GET /content/user/home/people-search.html HTTP/1.1] com.day.cq.wcm.tags.IncludeTag Error while executing script content.jsp
Caused by: org.apache.sling.api.SlingException: javax.servlet.ServletException: java.lang.Exception: user person search is not available