Sponsored Content
Top Forums Shell Programming and Scripting Grep some values from XML file Post 302969991 by Lord Spectre on Thursday 31st of March 2016 05:31:07 AM
Old 03-31-2016
Grep some values from XML file

Dear community,
I have a big XML log file containing several rows splitted by tag: <ActivityLogRecord> and </ActivityLogRecord>. An example below.

What I need is read the file and extract some value from each tags and put them into one line (each line for every <ActivityLogRecord> tag).

So in the example the output should be:
Code:
COSID='88',true,Value='393290439266'

The problem where I'm scratching my head is that sometimes this field is missing: <WhoCalledOn>true</WhoCalledOn> and this could be reported twice, something like:
Code:
<Identifier Type='TelephoneNumber' Value='324234231443'/>
<Identifier Type='TelephoneNumber' Value='324234231443'/>

This means the output I need should be:
Code:
COSID='88',true,Value='393290439266',null
COSID='88',null,Value='393290439266',Value='393290439266'

In other words, if the tag WhoCalledOn is missing, I should report in output something like NULL, otherwise put the value like true o false. Same thing for the TelephoneNumber tag. If reported only one, the second column should be set as NULL, otherwise report the value.

Well, I know, this is not properly simple, that's why I'm asking to the expert! Smilie

Thank you
Lucas


Code:
<ActivityLogRecord>
   <Common COSID='88' DomainID='BL' EndTimeStamp='2016-03-23T10:00:00.10+01:00' MainAction='Modify Subscriber' ReferenceNumber='192.9.224.15-1455979927516' ServerID='omu234234' ServiceName='SPM' StartTimeStamp='2016-03-23T09:59:59.850+01:00' UserID='234234234234' UserTerminal='vxv_app_user'>
      <MainActionResult Description='ERROR: 0 - Action completed successfully' Status='Success'/>
   </Common>
   <ServiceSpecific>
      <Provisioning xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
         <Request>
            <Header>
               <Command>Modify</Command>
               <EntityIdentifiers>
                  <Identifier Value='324234231443'/>
               </EntityIdentifiers>
                <Data>
                   <Subscriber>
                      <WhoCalledOn>true</WhoCalledOn>
                   </Subscriber>
                </Data>
               <HostReference>Automatic</HostReference>
            </Header>
            <Data>
               <Subscriber>
                  <SubscriberCosName>8</SubscriberCosName>
                  <SubscriberDomainName>Default domain</SubscriberDomainName>
               </Subscriber>
            </Data>
         </Request>
      </Provisioning>
      <Provisioning xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
         <Response>
            <Header>
               <EntityIdentifiers>
                  <Identifier Type='TelephoneNumber' Value='324234231443'/>
               </EntityIdentifiers>
               <EntityName>Subscriber</EntityName>
               <HostReference>Automatic</HostReference>
               <ResponseStatus>Success</ResponseStatus>
            </Header>
         </Response>
      </Provisioning>
   </ServiceSpecific>
</ActivityLogRecord>

 

9 More Discussions You Might Find Interesting

1. Programming

Extracting Field values for XML file

i have an input file of XML type with data like <nx-charging:additional-parameter name="NX_INTERNATIONALIZED_CLID" value="919427960829"/><nx-charging:finalStatus>RESPONSE , Not/Applicable , OK</nx-charging:finalStatus></nx-charging:process> i want to extract data such that i get the output... (3 Replies)
Discussion started by: junaid.nehvi
3 Replies

2. UNIX for Dummies Questions & Answers

Extracting values from an XML file

Hello People, I have an xml file from which I need to extract the values of the parameters using UNIX shell commands. Ex : Input is like : <Name>Roger</Name> or <Address>MI</Address> I need the output as just : Roger or MI with the tags removed. Please help. (1 Reply)
Discussion started by: sushant172
1 Replies

3. Shell Programming and Scripting

Extract values from an XML File

Hi, I need to capture all the attributes with delete next to it. The source XML file is attached. The output should contain something like this below: Attributes = legacyExchangeDN Action = Delete Username = Hero Joker Loginid = joker09 OU =... (4 Replies)
Discussion started by: prvnrk
4 Replies

4. Shell Programming and Scripting

Comparing delta values of one xml file in other xml file

Hi All, I have two xml files. One is having below input <NameValuePair> <name>Daemon</name> <value>tcp:7474</value> </NameValuePair> <NameValuePair> <name>Network</name> <value></value> </NameValuePair> ... (2 Replies)
Discussion started by: sharsour
2 Replies

5. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

6. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

7. Shell Programming and Scripting

How to retrieve values from XML file and update them in the same position! PLEASE HELP?

Good Day All Im quiet new to ksh scripting and need a bit of your help. I am attempting to write a script that reads in an XML and extracts certain field values from an XML file. The values are all alphanumeric and consist of two components: e.g "Test 1". I need to to create a script that... (2 Replies)
Discussion started by: JulioAmerica
2 Replies

8. UNIX for Beginners Questions & Answers

How to change values in xml file?

I have xml file like below, i want change the values at default-value place of each argument name using shell script. like where argument name= protocol and default-value=tcp, where argument name =port and default-value= 7223, where argument name = username and default-value=test, example ... (12 Replies)
Discussion started by: s1s2s3s4
12 Replies

9. Shell Programming and Scripting

Extract values from xml file script

Hi, please help on this. I want extract values of xml file structure and print in determined way. <ProjectName> --> only appears once <StructList> --> is the top node <Struct> node --> could be more than 1 NameID, STX, STY, PRX, PRY --> appears only 1 time within each <Struct> node... (10 Replies)
Discussion started by: Ophiuchus
10 Replies
All times are GMT -4. The time now is 11:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy