i want to search
at java.lang.Object.wait(Native Method)
- waiting on <0x17351c50> (a weblogic.rjvm.ResponseImpl)
at weblogic.rjvm.ResponseImpl.waitForData(ResponseImpl.java:76)
- locked <0x17351c50> (a weblogic.rjvm.ResponseImpl)
at weblogic.rjvm.ResponseImpl.getTxContext(ResponseImpl.java:104)
at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:104)
at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:164)
at ROIDLookupImpl_WLStub.lookupROIDS(Unknown Source)
at weblogic.servlet.internal.HttpServer.lookupROIDS(HttpServer.java:1101)
at weblogic.servlet.internal.session.ReplicatedSessionContext.getROIDSFromRemote(ReplicatedSessionContext.java:309)
at weblogic.servlet.internal.session.ReplicatedSessionContext.getSessionInternal(ReplicatedSessionContext.java:421)
at weblogic.servlet.internal.ServletRequestImpl.getValidSession(ServletRequestImpl.java:2632)
at weblogic.servlet.internal.ServletRequestImpl.getSession(ServletRequestImpl.java:2248)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3742)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2766)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183) "
this pattern in a log file and count the number of times it occurs in the large log file using unix.
so how can i do that?
-
That isn't a pattern. It is an example, and other examples that you want to find are likely to be slightly differentStephen C– Stephen C2015-02-22 09:13:29 +00:00Commented Feb 22, 2015 at 9:13
-
no i need to find this expression in a file this is not an example in real problem i need to find this onlyAshish Joshi– Ashish Joshi2015-02-22 21:37:48 +00:00Commented Feb 22, 2015 at 21:37
-
1what Stephen C is trying to explain is that, although the error may be the same on many places, there may be small differences, in for example memory addresses.Frido Emans– Frido Emans2015-02-23 00:08:16 +00:00Commented Feb 23, 2015 at 0:08
3 Answers
you can try pcregrep, as suggested in this: https://stackoverflow.com/a/2686705/2380702
This line should output the number of occurences:
pcregrep -c -M -f testsnippet.txt logfile.txt
where logfile.txt is your log you want to scan, and testsnippet.txt contains your snippet, with line-endings replaced by \n, and all dots and brackets preceded by slashes. In other words:
at java\.lang\.Object\.wait\(Native Method\)\n - waiting on <0x17351c50> \(a weblogic\.rjvm\.ResponseImpl\)\n at weblogic\.rjvm\.ResponseImpl\.waitForData\(ResponseImpl\.java:76\)\n - locked <0x17351c50> \(a weblogic\.rjvm\.ResponseImpl\)\n at weblogic\.rjvm\.ResponseImpl\.getTxContext\(ResponseImpl\.java:104\)\n at weblogic\.rjvm\.BasicOutboundRequest\.sendReceive\(BasicOutboundRequest\.java:104\)\n at weblogic\.rmi\.internal\.BasicRemoteRef\.invoke\(BasicRemoteRef\.java:164\)\n at ROIDLookupImpl_WLStub\.lookupROIDS\(Unknown Source\)\n at weblogic\.servlet\.internal\.HttpServer\.lookupROIDS\(HttpServer\.java:1101\)\n at weblogic\.servlet\.internal\.session\.ReplicatedSessionContext\.getROIDSFromRemote\(ReplicatedSessionContext\.java:309\)\n at weblogic\.servlet\.internal\.session\.ReplicatedSessionContext\.getSessionInternal\(ReplicatedSessionContext\.java:421\)\n at weblogic\.servlet\.internal\.ServletRequestImpl\.getValidSession\(ServletRequestImpl\.java:2632\)\n at weblogic\.servlet\.internal\.ServletRequestImpl\.getSession\(ServletRequestImpl\.java:2248\)\n at weblogic\.servlet\.internal\.WebAppServletContext\.invokeServlet\(WebAppServletContext\.java:3742\)\n at weblogic\.servlet\.internal\.ServletRequestImpl\.execute\(ServletRequestImpl\.java:2766\)\n at weblogic\.kernel\.ExecuteThread\.execute\(ExecuteThread\.java:224\)\n at weblogic\.kernel\.ExecuteThread\.run\(ExecuteThread\.java:183\)
You may want to replace the memory addresses by something like <0x[0-9a-f]+>, to catch different addresses, but I have not tested this, since that was not your question :) Above example does exactly what you asked.
2 Comments
When you find an at at the start of the line add to your count and stop counting until you see a line that does not start with at.
awk 'BEGIN {count=0; boolCount=0}; /^at/ {if (boolCount==0) count++; boolCount=1}; !/^at/ {boolCount=0}; END {print "Found: " count} ' logfile
2 Comments
/^ at/. The script counts the number of blocks identified with an at at the beginning of the line.