Need get data from XML file through shell script..


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Need get data from XML file through shell script..

hi all, here is the sample log file and these errors are repeated in log file..
i need all the repeated time stamp ,severity and message tags needs to print in output file.. through shell script
Code:
 <log-message>
 <timestamp>2019-03-13T04:52:49.648-05:00</timestamp>
 <severity>ERROR</severity>
 <application-id>xxxxx</application-id>
 <subsystem-id>INTF</subsystem-id> 
<host-name>xxxx</host-name>
 <log-origin>PFL</log-origin>
 <thread-id>MCulEngine14</thread-id> 
<uid>606</uid> 
<message>cannot make thumbnail image</message>
 <user-id> </user-id> 
<additional-info> </additional-info>
</log-message>

Can any one help me on this.

OUTPUT should be on below manner:
Code:
 <timestamp>2019-03-13T04:52:49.648-05:00</timestamp>
<severity>ERROR</severity>
<message>cannot make thumbnail image</message>

 <timestamp>2019-03-13T04:52:49.648-05:00</timestamp>
<severity>ERROR</severity>
<message>cannot make thumbnail image</message>

Thanks in Advance,

Last edited by ravi; 3 Weeks Ago at 03:39 AM..
# 2  
Hello ravi,

Could you please try following once.
Code:
awk -F"[><]" '
/\/log-message/{
  if(value){
    print value
  }
  value=""
  next
}
/timestamp/{
  value="timestamp="$3
  next
}
/severity/{
  value=value ORS "severioty="$3
  next
}
/message/{
  value=value ORS "message="$3
}
END{
  if(value){
    print value
  }
}
'    Input_file

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Code:
awk '
/ERROR/                 {print prev ORS $0; flag=1}
/message/ && flag       {print; flag=0}
                        {prev = $0}
' file > out.log

This User Gave Thanks to nezabudka For This Post:
# 4  
Quote:
Originally Posted by RavinderSingh13
Hello ravi,

Could you please try following once.
Code:
awk -F"[><]" '
/\/log-message/{
  if(value){
    print value
  }
  value=""
  next
}
/timestamp/{
  value="timestamp="$3
  next
}
/severity/{
  value=value ORS "severity="$3
  next
}
/message/{
  value=value ORS "message="$3
}
END{
  if(value){
    print value
  }
}
'    Input_file

Thanks,
R. Singh
Hi Singh, Thanks for your help, the above code is giving the out put but i need out put which are related to severity=ERROR and message = cannot make thumbnail image .. these two conditions need to satisfy ..

Thanks.
# 5  
Quote:
Originally Posted by ravi
Hi Singh, Thanks for your help, the above code is giving the out put but i need out put which are related to severity=ERROR and message = cannot make thumbnail image .. these two conditions need to satisfy ..
Thanks.
Hello ravi,

2 things here.

1- For thanking any person for any useful post(s) you could HIT thanks button at bottom left corner of each post Smilie
2- For your question; you have to provide samples of input and output in correct needed manner on forums, we can't guess that; so please provide in your post with CODE TAGS(see how your first post was edited).

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 6  
Quote:
Originally Posted by RavinderSingh13
Hello ravi,

2 things here.

1- For thanking any person for any useful post(s) you could HIT thanks button at bottom left corner of each post Smilie
2- For your question; you have to provide samples of input and output in correct needed manner on forums, we can't guess that; so please provide in your post with CODE TAGS(see how your first post was edited).

Thanks,
R. Singh
hi Singh, this first time am using this forum, so am not aware to click that thanks button, because of that i conveyed my greetings in words, going forward i will do HIT thanks button

I have updated my requirement input and output. thanks for your suggestion. Please help me on this.

Last edited by ravi; 3 Weeks Ago at 03:41 AM..
# 7  
With your amended spec, try also
Code:
grep -E "<(timestamp|severity|message)" file | paste -sd"\t\t\n" | grep -E "ERROR.*thumbnail" | tr '\t' '\n'

These 2 Users Gave Thanks to RudiC For This Post:
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
How to Parse the XML data along with the URL in Shell Script?
Megala
Hi, Can anybody help to solve this. I want to parse some xmldata along with the URL in the Shell. I'm calling the URL via the curl command Given below is my shell script file export...... Shell Programming and Scripting
7
Shell Programming and Scripting
Convert XML to Data File in Shell Script
ragha81
Hi All, I will be getting a huge XML file with a lot of records in it. I need to convert it into multiple data files. SAMPLE XML FILE <ABSProductCatalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <ProductSalesHierachy> - <Portfolios> - <Portfolio productCode="P1"> ...... Shell Programming and Scripting
8
Shell Programming and Scripting
How to remove xml namespace from xml file using shell script?
Gary1978
I have an xml file: <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only. I tried using sed...... Shell Programming and Scripting
10
Shell Programming and Scripting
Help with shell script to extract data from XML file
yajaykumar
Hello Scripting Gurus, I need help with extracting data from the XML file using shell script. The data is in a large XML and I need to extract the id values of all completedworkflows. Here is a sample of it. Input and output data is also in the attached text files. <wfregistry>...... Shell Programming and Scripting
5
Shell Programming and Scripting
extract data from xml- shell script using awk
nishana
Hi, This is the xml file that i have. - <front-servlet platform="WAS4.0" request-retriever="SiteMinder-aware" configuration-rescan-interval="60000"> <concurrency-throttle maximum-concurrency="50" redirect-page="/jsp/defaulterror.jsp" /> - <loggers> <instrumentation...... Shell Programming and Scripting
5
Shell Programming and Scripting