0

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?

3
  • That isn't a pattern. It is an example, and other examples that you want to find are likely to be slightly different Commented 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 only Commented Feb 22, 2015 at 21:37
  • 1
    what 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. Commented Feb 23, 2015 at 0:08

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Yea ... the problem with grep / fgrep / egrep is that they don't cope with patterns that span multiple lines.
added full working example
0

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

no i need to count the number of occurrence of the whole block that whole code is repeating in another file if i will count at it is coming 17 times in one block where it need to be counted 1 only.
When you have 17 at's in one block without lines that do not have an at, it will be counted only once, thanks to the boolCount. My mistake is that you might need to add some spaces or a tab between ^ and at: /^ at/. The script counts the number of blocks identified with an at at the beginning of the line.
0
printf "multi\nline\ninput\n" | grep -Pzo "(?s)mul.*put" | wc -l

you'll have to divide that by number of lines you expect your multiline pattern to span though.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.