Data Extract from XML Log File

Please help me out to extract the Data from the XML Log files.

So here is the data

ERROR|2010-08-26 00:05:52,958|SERIAL_ID=128279996|ST=2010-08-2600:05:52|DEVICE=113.2.21.12:601|TYPE=TransactionLog
|LOG_LEVEL=6|CLASS=Gateway|OBJECT=/services/olive|PROVIDERID=http://plss2132-vip.corp.sprint.com:7003
/bnc/services/EsaPort|CONSUMERID=|OPERATION_NAME=getEsaList|MsgID=|TOTAL_TIME=9385|DP_TIME=13|REQUEST_MESSAGE=<soapenv:Envelop
e xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://sch
emas.xmlsoap.org/soap/envelope/"><soapenv:Body><getEsaList xmlns="http://olive.sprint.com/jws/esa">
<billingAccountNumber xmlns=""> 2345689</billingAccountNumber><DeviceNumber xmlns="">null</DeviceNumber><startDate xmlns="">20100526</startD
ate><endDate xmlns="">20100826</endDate><applicationId xmlns="">eCare</applicationId></getEsaList></soapenv:Body></soapenv:Env
elope>|RESPONSE_MESSAGE=<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2
001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Serve
r.generalException</faultcode><faultstring/><detail><ns1:fault xmlns:ns1="http://olive.com/jws/esa"><message>No Electron
ic Service Agreement found within Olive for the Account NUmber and date criteria provided</message>

Only thing is im interested for only 2 fields

<billingAccountNumber xmlns=""> 2345689</billingAccountNumber>
<Message>

Please help me out.

I know this is still not complete but i m going for lunch will post after that.

sed -n '/<message>/,/<\/message>/p' filename

Try:

awk '{gsub(/\n/," ")}/^billingAccountNumber/||/^message/{printf RS$0; getline; print RS$0}' RS='<' infile

Result:

<billingAccountNumber xmlns=""> 2345689</billingAccountNumber>
<message>No Electron ic Service Agreement found within Olive for the Account NUmber and date criteria provided</message>

Please have look into this. The search should be done from multiple files . File names range is given like this

Service_LogGroup1
Service_LogGroup2
Service_LogGroup3
Service_LogGroup4
Service_LogGroup5

Im getting this error.

awk '{gsub(/\n/," ")}/^billingAccountNumber/||/^message/{printf RS$0; getline; print RS$0}' RS='<' Service_LogGroup[1-5]_2010-08-26.log
awk: syntax error near line 1
awk: illegal statement near line 1

Hi, you should be able to specify multiple files..
Are you on Solaris? Then use nawk or /usr/xpg4/bin/awk instead of standard awk

Im Using Solaris 10, so shall i use NAWK

Either one...

Im using NAWK, but still the same error

 nawk '{gsub(/\n/," ")}/^billingAccountNumber/||/^message/{printf RS$0; getline; print RS$0}' RS='<' dp_EsaService_LoggerGroup[1-5]_2010-08-26.log
nawk: can't open file Service_LogGroup[1-5]_2010-08-26.log
 source line number 1

That is a different error. nawk cannot find the file. Check if Service_LogGroup[1-5]_2010-08-26.log exists.

#!/bin/bash
data="$(<file)"
bill="${data##*<billingAccountNumber xmlns=\"\">}"
bill=${bill%%</billingAccountNumber>*}
msg=${data##*<message>}
msg=${msg%%<\/message>}
echo "$bill $msg"