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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
10-17-2007, 01:37 AM
|
#1
|
LQ Newbie
Registered: Sep 2002
Location: mangalore,india
Distribution: redhat
Posts: 28
Rep:
|
awk help - matching
(Please read my previous post "awk help")
Hi all,
I have a log file with 2 types of blocks
1) clientRequest
2) clientRequestResponse
####<Aug 30, 2007 10:56:30 AM IST><soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<clientRequest xmlns:m="http://www.openuri.org/">
..................
.................
.................
</clientRequest>
####<Aug 29, 2007 10:56:30 AM IST><soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<clientRequestResponse xmlns:m="http://www.openuri.org/">
...............
..................
..................
</clientRequestResponse>
Now using sed/awk i want to extract
1)all the clientRequest block (also m:clientRequestResponse,ns:clientRequestResponse etc)
2)all the clientRequestResponse block (also m:clientRequestResponse,ns:clientRequestResponse etc)
3)all the clientRequest block for a given date eg Aug 30, 2007 (also m:clientRequest,ns:clientRequest etc)
4)all the clientRequestResponse block for a given date eg Aug 30, 2007
(also m:clientRequest,ns:clientRequest etc)
Thanks and Regards,
uttam hoode
Code:
####<Aug 30, 2007 10:56:30 AM IST> <Info> <ALSB Logging> <saturn> <AdminServer> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1188451590854> <000000> < [Name_ID_Mapping, Name_ID_Mapping_request, Mapping ID_Name, REQUEST] +++++++++NProxy Request++++++++++: <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<m:clientRequest xmlns:m="http://www.openuri.org/">
<env:EaiEnvelope xmlns:env="http://eai.aaan.in/Envelope">
<env:Domain>AuctionPortal</env:Domain>
<env:Service>ece</env:Service>
<env:Sender>abl_ap</env:Sender>
<env:MessageId>aaaa</env:MessageId>
<env:Language>en</env:Language>
<env:UserId>abl_ap</env:UserId>
<env:CorrelationId>A001</env:CorrelationId>
<env:Payload>
<ec:eceData xmlns:ec="http://eai.aaa.in/ece">
<ec:Request>
<ec:Operation_Name>authenticateCustomerForAuctionPortal</ec:Operation_Name>
<ec:CustDetails_InputData>
<ec:MSISDN>989880000065</ec:MSISDN>
<ec:language>en</ec:language>
<ec:newPassword>password</ec:newPassword>
</ec:CustDetails_InputData>
</ec:Request>
</ec:eceData>
</env:Payload>
</env:EaiEnvelope>
</m:clientRequest>
</soapenv:Body>>
####<Aug 30, 2007 10:56:31 AM IST> <Info> <ALSB Logging> <saturn> <AdminServer> <[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1188451591466> <000000> < [Name_ID_Mapping, Name_ID_Mapping_response, Response Stage, RESPONSE] +++++++NPResponse+++++++++: <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<m:clientRequestResponse xmlns:m="http://www.openuri.org/">
<env:EaiEnvelope xmlns:env="http://eai.aaan.in/Envelope">
<env:Domain>AuctionPortal</env:Domain>
<env:Service>ece</env:Service>
<env:Sender>abl_ap</env:Sender>
<env:MessageId>aaaI_AP</env:MessageId>
<env:Language>en</env:Language>
<env:UserId>abl_ap</env:UserId>
<env:CorrelationId>A001</env:CorrelationId>
<env:Payload>
<ns1:eceData xmlns:ns1="http://eai.aaa.in/ece" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ns1:Response>
<ns1:Result_OutputData>
<ns1:resultCode>0</ns1:resultCode>
<ns1:resultMessage>Operation Completed Successfully.</ns1:resultMessage>
<ns1:reference_ID>1</ns1:reference_ID>
</ns1:Result_OutputData>
<ns1:CustDetails_OutputData>
<ns1:firstName>N</ns1:firstName>
<ns1:lastName>N</ns1:lastName>
<ns1:Customer_Type>N</ns1:Customer_Type>
<ns1:status>AC</ns1:status>
<ns1:isLocked>false</ns1:isLocked>
<ns1:isBlocked>false</ns1:isBlocked>
<ns1:isFirstLogin>true</ns1:isFirstLogin>
<ns1:hintQuestion>test</ns1:hintQuestion>
<ns1:hintAnswer>test</ns1:hintAnswer>
<ns1:lastLoginDateTime>2007-08-30T05:14:23.000Z</ns1:lastLoginDateTime>
<ns1:BSSUBSCODE>99999</ns1:BSSUBSCODE>
<ns1:ACCOUNT_NO>99999</ns1:ACCOUNT_NO>
<ns1:isAuction>Y</ns1:isAuction>
</ns1:CustDetails_OutputData>
</ns1:Response>
</ns1:eceData>
</env:Payload>
</env:EaiEnvelope>
</m:clientRequestResponse>
</soapenv:Body>>
####<Aug 30, 2007 10:57:27 AM IST> <Info> <ALSB Logging> <saturn> <AdminServer> <[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1188451647464> <000000> < [Name_ID_Mapping, Name_ID_Mapping_request, Mapping ID_Name, REQUEST] +++++++++NProxy Request++++++++++: <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<m:clientRequest xmlns:m="http://www.openuri.org/">
<env:EaiEnvelope xmlns:env="http://eai.aaan.in/Envelope">
<env:Domain>MobileLoadedPortal</env:Domain>
<env:Service>ece</env:Service>
<env:Sender>abl_mp</env:Sender>
<env:MessageId>aaaI_MLP</env:MessageId>
<env:Language>en</env:Language>
<env:UserId>abl_mp</env:UserId>
<env:CorrelationId>A001</env:CorrelationId>
<env:Payload>
<ec:eceData xmlns:ec="http://eai.aaa.in/ece">
<ec:Request>
<ec:Operation_Name>getCustomerInfo</ec:Operation_Name>
<ec:CustDetails_InputData>
<ec:MSISDN>989880000065</ec:MSISDN>
<ec:language>en</ec:language>
</ec:CustDetails_InputData>
</ec:Request>
</ec:eceData>
</env:Payload>
</env:EaiEnvelope>
</m:clientRequest>
</soapenv:Body>>
Last edited by uttam_h; 10-17-2007 at 01:40 AM.
|
|
|
10-17-2007, 04:33 AM
|
#2
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Sorry, but what do you mean when you say you "want to extract
a block"? You're trying to split the file into chunks?
Can you provide a sample of what you expect to see after
that "extraction"?
Cheers,
Tink
|
|
|
10-17-2007, 04:54 AM
|
#3
|
LQ Newbie
Registered: Sep 2002
Location: mangalore,india
Distribution: redhat
Posts: 28
Original Poster
Rep:
|
there are 2 types of block in the above log
1) clientRequest
Code:
####<Aug 30, 2007 10:56:30 AM IST> <Info> <ALSB Logging> <saturn> <AdminServer> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1188451590854> <000000> < [Name_ID_Mapping, Name_ID_Mapping_request, Mapping ID_Name, REQUEST] +++++++++NProxy Request++++++++++: <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<m:clientRequest xmlns:m="http://www.openuri.org/">
<env:EaiEnvelope xmlns:env="http://eai.aaan.in/Envelope">
<env:Domain>AuctionPortal</env:Domain>
<env:Service>ece</env:Service>
<env:Sender>abl_ap</env:Sender>
<env:MessageId>aaaa</env:MessageId>
<env:Language>en</env:Language>
<env:UserId>abl_ap</env:UserId>
<env:CorrelationId>A001</env:CorrelationId>
<env:Payload>
<ec:eceData xmlns:ec="http://eai.aaa.in/ece">
<ec:Request>
<ec:Operation_Name>authenticateCustomerForAuctionPortal</ec:Operation_Name>
<ec:CustDetails_InputData>
<ec:MSISDN>989880000065</ec:MSISDN>
<ec:language>en</ec:language>
<ec:newPassword>password</ec:newPassword>
</ec:CustDetails_InputData>
</ec:Request>
</ec:eceData>
</env:Payload>
</env:EaiEnvelope>
</m:clientRequest>
</soapenv:Body>>
2) clientRequestResponse
Code:
####<Aug 30, 2007 10:56:31 AM IST> <Info> <ALSB Logging> <saturn> <AdminServer> <[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1188451591466> <000000> < [Name_ID_Mapping, Name_ID_Mapping_response, Response Stage, RESPONSE] +++++++NPResponse+++++++++: <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<m:clientRequestResponse xmlns:m="http://www.openuri.org/">
<env:EaiEnvelope xmlns:env="http://eai.aaan.in/Envelope">
<env:Domain>AuctionPortal</env:Domain>
<env:Service>ece</env:Service>
<env:Sender>abl_ap</env:Sender>
<env:MessageId>aaaI_AP</env:MessageId>
<env:Language>en</env:Language>
<env:UserId>abl_ap</env:UserId>
<env:CorrelationId>A001</env:CorrelationId>
<env:Payload>
<ns1:eceData xmlns:ns1="http://eai.aaa.in/ece" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ns1:Response>
<ns1:Result_OutputData>
<ns1:resultCode>0</ns1:resultCode>
<ns1:resultMessage>Operation Completed Successfully.</ns1:resultMessage>
<ns1:reference_ID>1</ns1:reference_ID>
</ns1:Result_OutputData>
<ns1:CustDetails_OutputData>
<ns1:firstName>N</ns1:firstName>
<ns1:lastName>N</ns1:lastName>
<ns1:Customer_Type>N</ns1:Customer_Type>
<ns1:status>AC</ns1:status>
<ns1:isLocked>false</ns1:isLocked>
<ns1:isBlocked>false</ns1:isBlocked>
<ns1:isFirstLogin>true</ns1:isFirstLogin>
<ns1:hintQuestion>test</ns1:hintQuestion>
<ns1:hintAnswer>test</ns1:hintAnswer>
<ns1:lastLoginDateTime>2007-08-30T05:14:23.000Z</ns1:lastLoginDateTime>
<ns1:BSSUBSCODE>99999</ns1:BSSUBSCODE>
<ns1:ACCOUNT_NO>99999</ns1:ACCOUNT_NO>
<ns1:isAuction>Y</ns1:isAuction>
</ns1:CustDetails_OutputData>
</ns1:Response>
</ns1:eceData>
</env:Payload>
</env:EaiEnvelope>
</m:clientRequestResponse>
</soapenv:Body>>
log has many such entries....using awk i want to extract clientRequestResponse or clientRequest. also based on date
Regards,
uttam hoode
|
|
|
10-17-2007, 05:03 AM
|
#4
|
LQ Newbie
Registered: Oct 2007
Location: India
Distribution: ubuntu, redhat
Posts: 5
Rep:
|
You can consider "<" as your field separator cos every new Tag starts with "<" .
Hence :
awk -F "<" ClientRequest -> this will give all the Log entries...
I hope u can get my idea....
|
|
|
10-17-2007, 05:30 AM
|
#5
|
Member
Registered: Nov 2005
Location: Davao City, Philippines
Distribution: RHEL, CentOS, Ubuntu, Mint
Posts: 139
Rep:
|
Hi! you could use this post as your reference. This would give you an idea to get started...
http://www.linuxquestions.org/questi...e-line-592417/
|
|
|
10-17-2007, 05:44 AM
|
#6
|
Member
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212
Rep:
|
_If I understand correctly_ :
1. To extract the different blocks:
clientRequest
Code:
awk '/^###/{x=$0}
$0~v{print x"\n"$0;f=1;next}
f&&/<\/soapenv/{print;f=0}f
' v="<m:clientRequest " filename
clientRequestResponse
Code:
awk '/^###/{x=$0}
$0~v{print x"\n"$0;f=1;next}
f&&/<\/soapenv/{print;f=0}f
' v="<m:clientRequestR" filename
clientRequest for a given date:
Code:
awk '/^###/&&$0~dt{x=$0;f1=1}
f1&&$0~v{print x"\n"$0;f=1;next}
f&&/<\/soapenv/{print;f=f1=0}f
' dt="Aug 23, 2007" v="<m:clientRequest " filename
clientRequestResponse for a given date:
Code:
awk '/^###/&&$0~dt{x=$0;f1=1}
f1&&$0~v{print x"\n"$0;f=1;next}
f&&/<\/soapenv/{print;f=f1=0}f
' dt="Aug 30, 2007" v="<m:clientRequestR" filename
|
|
|
10-17-2007, 01:20 PM
|
#7
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Quote:
Originally Posted by uttam_h
there are 2 types of block in the above log
1) clientRequest
2) clientRequestResponse
log has many such entries....using awk i want to extract clientRequestResponse or clientRequest. also based on date
|
Yes, I had seen those...
You *still* didn't say what exactly you mean by extract,
but I'll assume that you're trying to split out the whole
chunks w/o any reformatting.
If the structure of the log is consistently like the
tiny snippet you provided the easiest way to deal
with it would be like so:
Code:
awk 'BEGIN{RS="\n\n"; FS="\n"; ORS=RS; OFS=FS} /<Aug 30, 2007/ && /clientRequestResponse /' log
Cheers,
Tink
Last edited by Tinkster; 10-17-2007 at 01:22 PM.
Reason: typo
|
|
|
10-17-2007, 03:20 PM
|
#8
|
Member
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212
Rep:
|
Quote:
Originally Posted by Tinkster
[...]
If the structure of the log is consistently like the
tiny snippet you provided the easiest way to deal
with it would be like so:
Code:
awk 'BEGIN{RS="\n\n"; FS="\n"; ORS=RS; OFS=FS} /<Aug 30, 2007/ && /clientRequestResponse /' log
|
Or just:
Code:
awk '/<Aug 30, 2007/&&/clientRequestResponse /' RS="\n\n" file
As already stated there are a few particularities here:
1. The above solution works only with GNU Awk (and may be tawk,
cannot check right now), but this is a Linux forum, so that's ok
2. Must pay attention for possible "record too long" errors
(not with the given format, of course).
|
|
|
All times are GMT -5. The time now is 03:00 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|