How to extract data from XML file using shell scripting?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract data from XML file using shell scripting?
# 1  
Old 08-12-2013
How to extract data from XML file using shell scripting?

Hi ,
I have input file as XML. following are input data
#complex.xml


Code:
Code:
<?xml version="1.0" encoding="UTF-8"?><TEST_doc xmlns="http://www.w3.org/2001/XMLSchema-instance">  <ENTRY uid="123456">    <protein>      <name>PROT001</name>      <organism>Human</organism>      <class>cytoplasmic</class>    </protein>    <xrefs>      <xref>          <database>Ensembl</database>          <accn>ENSG00000105829</accn>      </xref>      <xref>          <database>UNIPROT</database>          <accn>Q12345</accn>      </xref>    </xrefs>  </ENTRY>  <ENTRY uid="45678">    <protein>      <name>PROT002</name>      <organism>Human</organism>      <class>nuclear</class>    </protein>    <xrefs>      <xref>          <database>Ensembl</database>          <accn>ENSG00000105333</accn>      </xref>      <xref>          <database>UNIPROT</database>          <accn>Q14789</accn>      </xref>    </xrefs>  </ENTRY></TEST_doc>

i want to extract data from this file and i tried below query.
Code:
cat complex.xml | xml sel -t -m //xref -v "concat(../../protein/name,' ',../../protein/class,' ',./database,' ',./accn)" -n

but it is not giving any output...but this query is working when instead of xmlns i am writing xmlns:xsi="...."
but my input file is having only xmlns="..."

please help me ...

Thanks in advance..

Last edited by joeyg; 08-12-2013 at 09:08 AM.. Reason: CodeTags for all data and commands
# 2  
Old 08-12-2013
Please use code tags
Give an example on what output you like to have

Lik this?
Code:
awk '{gsub(/<[^>]*>/, " ");$1=$1}1' complex.xml
PROT001 Human cytoplasmic Ensembl ENSG00000105829 UNIPROT Q12345 PROT002 Human nuclear Ensembl ENSG00000105333 UNIPROT Q14789



EDIT: Some change
Code:
awk '{gsub(/<[^>]*>/, " ");$1=$1;gsub(/PROT[0-9]/,"\n&")}1' complex.xml

PROT001 Human cytoplasmic Ensembl ENSG00000105829 UNIPROT Q12345
PROT002 Human nuclear Ensembl ENSG00000105333 UNIPROT Q14789


Last edited by Jotne; 08-12-2013 at 08:37 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract Data from XML file.

Hi Guys, I am in a need to extract data from a xml file. The XML file format is as below. <data jsxnamespace="propsbundle" locales=""> <locale> <!--Error messages starts--> <record jsxid="CHARPAIR001" jsxtext=" must be selected"></record> <record... (1 Reply)
Discussion started by: Showdown
1 Replies

2. Shell Programming and Scripting

How to extract data from xml file using shell scripting?

Hi evry1, This is my 1st post in this forum.Pls help me I want to extract some data froma xml file which has 2000 lines using shell scripting. Actually my xml file has some "audio and video codes" which i need to arrange in a column wise format after extracting it using shell scripting.I... (4 Replies)
Discussion started by: arun_kohan
4 Replies

3. Shell Programming and Scripting

Extract data from XML file

Hi , I have input file as XML. following are input data #complex.xml <?xml version="1.0" encoding="UTF-8"?> <TEST_doc xmlns="http://www.w3.org/2001/XMLSchema-instance"> <ENTRY uid="123456"> <protein> <name>PROT001</name> <organism>Human</organism> ... (1 Reply)
Discussion started by: mohan sharma
1 Replies

4. Shell Programming and Scripting

Shell script to extract data in repeating tags from xml

Hi, I am new to shell scripting. I need to extract data between repeating tags from an xml file and store the data in an array to process it further. <ns1:root xmlns:ns1="http://example.com/config"> <ns1:interface>in1</ns1:interface> <ns1:operation attribute1="true" attribute2="abd"... (2 Replies)
Discussion started by: sailendra
2 Replies

5. Shell Programming and Scripting

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... (9 Replies)
Discussion started by: raghunsi
9 Replies

6. Shell Programming and Scripting

Shell scripting to extract data from file

Hi, i want to fetch the data from the alert log file, for a particular time interval. Example : Alert log content : Thu Mar 18 08:47:36 2010 Completed: alter database open Thu Mar 18 19:13:38 2010 MMNL absent for 6390 secs; Foregrounds taking over Fri Mar 19 08:30:52 2010... (1 Reply)
Discussion started by: Pinki018
1 Replies

7. Shell Programming and Scripting

sed or awk to extract data from Xml file

Hi, I want to get data from Xml file by using sed or awk command. I want to get the following result : mon titre 1;Createur1;Dossier1 mon titre 1;Createur1;Dossier1 and save it in cvs file (fichier.cvs). FROM this Xml file (test.xml): <playlist version="1"> <trackList> <track>... (1 Reply)
Discussion started by: yeclota
1 Replies

8. Shell Programming and Scripting

Help with shell script to extract data from XML file

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>... (5 Replies)
Discussion started by: yajaykumar
5 Replies

9. Shell Programming and Scripting

extract specific data from xml format file.

Hi, I need to extract the start time value (bold, red font) under the '<LogEvent ID="Timer Start">' tag (black bold) from a file with the following pattern. There are other LogEventIDs listed in the file as well, making it harder for me to extract out the specific start time that I need. . .... (7 Replies)
Discussion started by: 60doses
7 Replies

10. Shell Programming and Scripting

extract data from xml- shell script using awk

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... (5 Replies)
Discussion started by: nishana
5 Replies
Login or Register to Ask a Question