Searching for a pattern and extracting records related to that pattern

Hi there,

Looking forward to your advice for the below:

I have a file which contains 2 paragraphs related to a particular pattern. I have to search for those paragraphs from a log file and then print a particular line from those paragraphs.

Sample:

I have one file with the fixed patterns

CCRC_28778426
CCRC_1364658755732
CCRC_1364658755738
CCRC_1364658755917
CCRC_1364658755941
CCRC_1364658756068
CCRC_1364658756084
CCRC_1364658756086
CCRC_1364658756228
CCRC_1364658756472

Using the fix patterns, I have to search for 2 paragraphs related to that pattern. Once that is found, then I have to print the timestamp when those requests came.

2013-03-31 14:12:59.100805 < APP > (thr:1) [main] com.comptel.eventlink.node.AdapterNodeSingleton processInputRecord
FINE: Processing input record.
2013-03-31 14:12:59.101085 < APP > (thr:1) [main] com.comptel.mc.node.eaibln.NodeApplication process
FINE: Incoming request from: XMLMQ inputType:  inputLink: OUTRECORD
F __JMS_MESSAGE_ID__ ID:414d51204545534f3933315020202020513dbaaa2d289d91
F __RESEND_COUNT__ 0
B OCGWRequest
B Header
F RqId CCRC_28778426
F RqMode 1
F TrySequence 1
F AppId 012
F GatewayAppId 011
F Bulk no
F RqTimeStamp 2013-03-31T14:12:59
F Version 1.0.2
.
B Body
B Request
F SubRqId 1
F FunctionId 2
F ServiceId 119
F SubscriberId 966569297575
F MainAccAmount 9641
F RefillProfileId 8
2013-03-31 14:12:59.204187 < APP > (thr:1) [main] com.comptel.mc.node.eaibln.xmlmqResponse writeCdrFile
INFO: Error response for MSGID: ID:414d51204545534f3933315020202020513dbaaa2d289d91, RqID:CCRC_28778426 {responseCode=1, RqTim
eStamp=2013-03-31T14:12:59, GatewayAppId=011, RefillProfileId=8, FunctionId=2, RqMode=1, RollBackPossible=TRUE, Bulk=no, respo
nseFrom=UCIP, RollBackBy=CREDIT, MainAccAmount=9641, SubscriberId=966569297575, ApplicationId=012, SubRqId=1, TrySequence=1, r
esponseErrorCode=W220100, OrigRqId=null, responseErrorDescription= ResponseCode 1 - Ok but supervision period exceeded, respon
seStatus=2, responseBackEnd=rc1air5, ServiceId=119, responseTransactionId=195891364728081230}
2013-03-31 14:12:59.204393 < APP > (thr:1) [main] com.comptel.mc.node.eaibln.xmlmqResponse sendResponse
FINE: Outgoing response to XMLMQ_RESPONSE record: RECORD
F __JMS_MESSAGE_ID__ ID:414d51204545534f3933315020202020513dbaaa2d289d91
B OCGWResponse
B Header
F RqId CCRC_28778426
F RqStatus 2
.
B Body
B Response
F SubRqId 1
F TransactionId CCRC_28778426:1
F SubRqStatus 2
F ErrorCode W220100
F ErrorDescription Successful, but supervision period exceeded:  ResponseCode 1 - Ok but supervision period exceeded

Please advise

Your specification doesn't yield too much information, nor do the few word printed in yellow, and a sample output is missing entirely. Wild guessing on my part yielded this:

$ awk 'FNR==NR     {A[$1]=1;next}
       /< APP >/   {TS=$1" "$2}
       ($3 in A)   {print TS; TS=""}
      ' file1 file2
2013-03-31 14:12:59.101085
2013-03-31 14:12:59.204393

which are NOT the time stamps in yellow, but the last ones encountered before the "fix pattern" was found.

If that does not fulfill your needs (and I don't expect it to), be way more specific describing/detailing your request!

Dear Rudic,

Every sample fixed pattern like (CCRC_28778426), there are hundreds of such fixed patters, has a OCGWRequest paragraph and a OCGWResponse paragraph in a log file. Using the fixed pattern/s, I have to search its related Request and Response paragraph and when I get those I have to print the timestamp which is mentioned above the lines

In request paragraph:

In response paragraph:

Hope this clears the confusion. Please let me know if you require any more clarification.

You didn't comment on the results of my proposal, nor did you show the desired output format. What do you expect?

Please read carefully through your specification in post #1

and ask yourself if it can be clear to someone not familiar with your problem.