LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-17-2013, 08:04 AM   #1
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 75

Rep: Reputation: 15
How to find a specific word between two lines having same another word..


Hi,

First of all apologies for that poor statement I wrote - my bad english :-(

Let me elaborate in example what I exactly need.

I have a java app log file containing different exceptions.

Code:
$ vi java.log

2013-01-23 21:19:32,621 INFO [STDOUT] (my-nio-server-WorkerThread-4029) [LCDS]01/23/2013 GatewayEndpoint 'gateway-endpoint' failed to process a synchronized authentication.
flex.messaging.security.SecurityException: External login command required. Please check your security configuration.
at flex.messaging.security.LoginManager.login(LoginManager.java:245)
at flex.messaging.endpoints.GatewayEndpoint$GatewayEndpointProtocolHandler.processAuthenticationSyncOperation(GatewayEndpoint.java:874)
at flex.messaging.endpoints.GatewayEndpoint$GatewayEndpointProtocolHandler.processReceivedGatewayMessage(GatewayEndpoint.java:836)
at flex.messaging.endpoints.GatewayEndpoint$GatewayEndpointProtocolHandler.processReceivedMessage(GatewayEndpoint.java.exception:779)
at flex.messaging.endpoints.AMFSocketProtocolHandler.processReceivedMessageChunk(AMFSocketProtocolHandler.java:158)
at flex.messaging.io.amfsocket.AMFSocketInput.read(AMFSocketInput.java:139)
at flex.messaging.endpoints.AMFSocketProtocolHandler.doRead(AMFSocketProtocolHandler.java:132)
2013-01-23 22:30:44,044 INFO [org.apache.axis2.transport.http.HTTPSender] (http-0.0.0.0-8080-9) Unable to sendViaPost to url[https://www.zuora.com/apps/services/a/43.0]
org.apache.commons.httpclient.ConnectionPoolTimeoutException: Timeout waiting for connection
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.doGetConnection(MultiThreadedHttpConnectionManager.java:497)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getConnectionWithTimeout(MultiThreadedHttpConnectionManager.java:416)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:153)
at org.apache.commons.httpclient.HttpClient.execute(HttpClient.java.exception:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
2013-01-23 22:30:44,044 INFO [org.apache.axis2.transport.http.HTTPSender] (http-0.0.0.0-8080-9) Unable to sendViaPost to url[https://www.zuora.com/apps/services/a/43.0]
org.apache.commons.httpclient.ConnectionPoolTimeoutException: Timeout waiting for connection
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.doGetConnection(MultiThreadedHttpConnectionManager.java:497)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getConnectionWithTimeout.exception(MultiThreadedHttpConnectionManager.java:416)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:153)
I want to find how many "exception" words are there between line having "INFO" word in them.

ie. for example, in below section there are two exception errors..

Code:
2013-01-23 21:19:32,621 INFO [STDOUT] (my-nio-server-WorkerThread-4029) [LCDS]01/23/2013 GatewayEndpoint 'gateway-endpoint' failed to process a synchronized authentication.
flex.messaging.security.SecurityException: External login command required. Please check your security configuration.
at flex.messaging.security.LoginManager.login(LoginManager.java:245)
at flex.messaging.endpoints.GatewayEndpoint$GatewayEndpointProtocolHandler.processAuthenticationSyncOperation(GatewayEndpoint.java:874)
Unable to sendViaPost to url[https://www.zuora.com/apps/services/a/43.0]
org.apache.commons.httpclient.ConnectionPoolTimeoutException: Timeout waiting for connection
2013-01-23 22:30:44,044 INFO [org.apache.axis2.transport.http.HTTPSender] (http-0.0.0.0-8080-9) Unable to sendViaPost to url
Thanks in advance.

Regards,
Ravi
 
Old 04-17-2013, 08:15 AM   #2
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,733

Rep: Reputation: 591Reputation: 591Reputation: 591Reputation: 591Reputation: 591Reputation: 591
Quote:
Originally Posted by say_hi_ravi View Post
I want to find how many "exception" words are there between line having "INFO" word in them.
Please provide a sample output file which corresponds to the sample input file already posted. That, along with your words, will help us to understand your goal.

Daniel B. Martin
 
Old 04-18-2013, 03:47 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,842

Rep: Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004
Perhaps something like this?

Code:
awk '/INFO/ { count[++n]=0 } ; /Exception/ { count[n]++ } ; END{ for (i in count){ printf "section %d has %d exceptions\n",i,count[i] } }' | sort -k1n
 
1 members found this post helpful.
Old 04-18-2013, 07:12 PM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,733

Rep: Reputation: 591Reputation: 591Reputation: 591Reputation: 591Reputation: 591Reputation: 591
Quote:
Originally Posted by David the H. View Post
Perhaps something like this?

Code:
awk '/INFO/ { count[++n]=0 } ; /Exception/ { count[n]++ } ; END{ for (i in count){ printf "section %d has %d exceptions\n",i,count[i] } }' | sort -k1n
I like this solution, and offer a minor improvement...
Code:
awk '/INFO/ {count[++n]=0}; /Exception/ {count[n]++};
  END{for (i=1;i<=n;i++)
  {printf "section %d has %d exceptions\n",i,count[i]}}' $InFile >$OutFile
...which produces the same result without needing the sort step.

Daniel B. Martin
 
1 members found this post helpful.
Old 04-18-2013, 07:37 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,842

Rep: Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004
Yeah, I should've thought of that. I hate having to fight with awk's lack of easy array control and tend towards the laziest approach. awk really needs to get a few built-in array and field range functions; splicing and sorting can be so annoying.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Read lines after a specific word. Kashif_Bash Programming 10 04-26-2012 05:06 AM
How to find all lines in a file that contains a particular word Coolsafe Linux - Newbie 6 11-14-2009 06:53 PM
print second word in 1st line along with 5th word in all the lines after the first bangaram Programming 5 08-31-2009 04:42 AM
substitute few words + change all the lines starting with a specific word + put blank rahmathullakm Programming 6 01-18-2009 12:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration