Xml multi parse question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Xml multi parse question
# 1  
Old 04-14-2014
Xml multi parse question

Code:
awk -F "[<>]" '/<Id>|<id>|<Source>|<source>|<Accession>|<accession>|<TestName>|<testname>/ {print $2, $3}' OFS='\t' Test.xml

The above code works great, but lets say I wanted the <Analyte> name (<Name>STAT3). The word <name> is unique so there will be multiple records pulled. Is there a way to make the name dependent on a word?

For example, STAT3 would be dependent on Analyte and all other records would be ignored? Thanks.
# 2  
Old 04-15-2014
I'm not following your question fully, perhaps you could show an example input line and what you want to match on in it?

Unless you just mean to ask how to choose a given field to match on, in which case, you can replace:
Code:
/<Id>|<id>|<Source>|<source>|<Accession>|<accession>|<TestName>|<testname>/

with
Code:
$2 ~ /<Id>|<id>|<Source>|<source>|<Accession>|<accession>|<TestName>|<testname>/

To have it only output lines where field 2 matches something in the list you've specified.
# 3  
Old 04-15-2014
Lets say I wanted the <Condition>|<name> which = Hyperimmunoglobulin E syndrome, but not any other occurrence of <name>.

Code:
awk -F "[<>]" ' $2 ~ /<Id>|<id>|<Source>|<source>|<Accession>|<accession>|<TestName>|<testname>|<Condition>|<name>/
{print $2, $3}' OFS='\t' GTR.doc > output.txt

As you can see the <name> is not unique, but there is a unique header associated with it. Thanks.
# 4  
Old 04-15-2014
If you are just looking for lines that match <Name>Hyperimmunoglobulin E syndrome, couldn't you just search for that instead of just <Name>?
ie
Code:
awk -F "[<>]" ' /<Id>|<id>|<Source>|<source>|<Accession>|<accession>|<TestName>|<testname>|<Condition>|<Name>Hyperimmunoglobulin E syndrome/
{print $2, $3}' OFS='\t' GTR.doc > output.txt

# 5  
Old 04-15-2014
Please give us the input and desired output, we can help
# 6  
Old 04-17-2014
xml multi parse

The input file is attached.

The desired out would be:

Id 508680
TestName Whole Exome Sequencing
Offerer Baylor Medical Genetics Laboratories Baylor College of Medicine
DirectorList Sarah Elsea, PhD, ABMG, FACMG, Diplomate of the American Board of Medical Genetics, Lab Director
DirectorList Christine Eng, MD, ABMG, FACMG, Diplomate of the American Board of Medical Genetics, Medical Director, Laboratory Director
DirectorList Marilyn Li, MD, ABMG, Diplomate of the American Board of Medical Genetics, Lab Director
DirectorList Ankita Patel, PhD, ABMG, Diplomate of the American Board of Medical Genetics, Lab Director
DirectorList Lee-Jun Wong, PhD, ABMG, Diplomate of the American Board of Medical Genetics, Lab Director

Code:
awk -F "[<>]" ' /<Id>|<id>|< TestName>|<testname>|<Offerer>|<offerer>|<DirectorList>|<sting>/ {print $2, $3}' OFS='\t' exome.doc > output.txt

Thanks.
# 7  
Old 04-17-2014
That attachment is:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE eSummaryResult PUBLIC "-//NLM//DTD esummary gtr 20140110//EN" "http://eutils.ncbi.nlm.nih.gov/eutils/dtd/20140110/esummary_gtr.dtd">
<eSummaryResult>
<DocumentSummarySet status="OK">
<DbBuild>Build140417-0530.1</DbBuild>

<DocumentSummary uid="508680">
        <Id>508680</Id>
        <Source>GTR</Source>
        <Accession>GTR000508680</Accession>
        <TestName>Whole Exome Sequencing</TestName>
        <TestType>Clinical</TestType>
        <ConditionList>
                <Condition>
                        <Name>Intellectual functioning disability</Name>
                        <Acronym></Acronym>
                        <CUI>C0025362</CUI>
                </Condition>
        </ConditionList>
        <Analytes>
        </Analytes>
        <GeneList>
        </GeneList>
        <Offerer>Baylor Medical Genetics Laboratories Baylor College of Medicine</Offerer>
        <OffererLocation>
                <Line1> 2450 Holcombe, Grand Blvd. - Sample Receiving Dock</Line1>
                <Line2></Line2>
                <Line3></Line3>
                <City>Houston</City>
                <State>Texas</State>
                <PostCode>77021-2024</PostCode>
                <Country>United States</Country>
        </OffererLocation>
        <OffererID>1006</OffererID>
        <DirectorList>
                <string>Sarah Elsea, PhD, ABMG, FACMG, Diplomate of the American Board of Medical Genetics, Lab Director</string>
                <string>Christine Eng, MD, ABMG, FACMG, Diplomate of the American Board of Medical Genetics, Medical Director, Laboratory Director</string>
                <string>Marilyn Li, MD, ABMG, Diplomate of the American Board of Medical Genetics, Lab Director</string>
                <string>Ankita Patel, PhD, ABMG, Diplomate of the American Board of Medical Genetics, Lab Director</string>
                <string>Lee-Jun Wong, PhD, ABMG, Diplomate of the American Board of Medical Genetics, Lab Director</string>
        </DirectorList>
        <Summary></Summary>
        <Flags>
        </Flags>
        <Method>
                <TopCategory>
                        <Name>Molecular Genetics</Name>
                        <CategoriesString>_C_______________</CategoriesString>
                        <CategoryList>
                                <Category>
                                        <Name>Sequence analysis of the entire coding region</Name>
                                        <Code>C</Code>
                                        <MethodList>
                                                <string>Next-Generation (NGS)/Massively parallel sequencing (MPS)</string>
                                        </MethodList>
                                </Category>
                        </CategoryList>
                </TopCategory>
        </Method>
        <AnalyticalValidity>Sensitivity 97%</AnalyticalValidity>
        <TargetPopulation></TargetPopulation>
        <Certifications>
                <Certification>
                        <CertificationType>MD - Maryland Department of Health and Mental Hygiene DHMH</CertificationType>
                        <id>1419</id>
                </Certification>
                <Certification>
                        <CertificationType>NY - New York State Department of Health NYSDOH</CertificationType>
                        <id>PFI-4584 Code 844052A2</id>
                </Certification>
                <Certification>
                        <CertificationType>FL - Florida Agency for Health Care Administration AHCA</CertificationType>
                        <id>L800012320</id>
                </Certification>
                <Certification>
                        <CertificationType>RI - State of Rhode Island Department of Health RIDOH</CertificationType>
                        <id>LCO00545</id>
                </Certification>
                <Certification>
                        <CertificationType>CLIA</CertificationType>
                        <id>45D0660090</id>
                </Certification>
                <Certification>
                        <CertificationType>CAP</CertificationType>
                        <id>2109314</id>
                </Certification>
        </Certifications>
        <StudyDesc></StudyDesc>
        <TestTargetList>
                <string>Human genome</string>
                <string>Whole exome</string>
        </TestTargetList>
        <ConditionCount>1</ConditionCount>
        <TestTargetCount>2</TestTargetCount>
        <Extra><![CDATA[]]></Extra>
</DocumentSummary>

</DocumentSummarySet>
</eSummaryResult>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

XML Splitting into multi files

Hi , I have a XML file like below file name : sample.xml <?xml version="1.0"?> <catalog> <author>Rajini</author> <title>XML Guide</title> <Text> </Text> <genre>Computer</genre> <price>44.95</price> </catalog> <?xml version="1.0"?> <catalog> ... (5 Replies)
Discussion started by: karthinvk
5 Replies

2. Shell Programming and Scripting

Parse XML For Values

Hi All, I want to parse XML to extract values of the tags to do further processing. The XML looks like <?xml version="1.0" encoding="ISO-8859-1"?> <allinput> <input A="2389906" B="install"> <C>111</C> <D>222</D> <E>333</E> <F></F> <G>444</G> <H></H> <I></I> <J></J> <K>C,D,E,G</K>... (6 Replies)
Discussion started by: rahulmittal87
6 Replies

3. Shell Programming and Scripting

Parse XML line

Hi I am having an xml file with lines like these <d name="T2tt_350_100" title="T2tt_012j_350_100_428p4_pPF_PU" add="1" color="4" ls="1" lw="2" normf="1" xsection="0.070152" EqLumi="94651.6"... (2 Replies)
Discussion started by: Alkass
2 Replies

4. Shell Programming and Scripting

SH script to parse string and return multi-line file

Hello all, I have been asked to exercise my shell scripting and it has been 10 plus years since I used to do it so I can not remember hardly anything and ask for your help. What I need to do is copy a line out of a file that can be 10 to 100 characters long, I then need to parse this line into... (3 Replies)
Discussion started by: Alivadoro
3 Replies

5. Shell Programming and Scripting

Parse XML

Hi all! I'm looking to write a quick script and in it I need to request an XML file from a service running on localhost and parse that XML file and output it. I'm looking to do it in bash although it doesn't really matter what shell it is in. The XML file returned would look like this: ... (3 Replies)
Discussion started by: mtehonica
3 Replies

6. Shell Programming and Scripting

Parse Multi-Section Configuration File

Hello all, Sample configuration file: username = root password = admin IpAddress = 192.168.2.90 HttpCommand = /getfile?hello.jpg Username = root2 Password = admin2 Passive = no Host = 192.168.1.100 Path = /uploads Username = root3 Password = adming Passive = no Host =... (10 Replies)
Discussion started by: LAVco
10 Replies

7. Shell Programming and Scripting

Parse an XML task list to create each task.xml file

I have an task definition listing xml file that contains a list of tasks such as <TASKLIST <TASK definition="Completion date" id="Taskname1" Some other <CODE name="Code12" <Parameter pname="Dog" input="5.6" units="feet" etc /Parameter> <Parameter... (3 Replies)
Discussion started by: MissI
3 Replies

8. Shell Programming and Scripting

Parse XML file

Hi, I need to parse the following XML data enclosed in <a> </a> XML tag using shell script. <X> ..... </X> <a> <b> <c>data1</c> <c>data2</c> </b> <d> <c>data3</c> </d> </a> <XX> ... </XX> (5 Replies)
Discussion started by: viki
5 Replies

9. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies

10. Programming

parse xml

Hi, I'm looking for an "easy" way to parse a xml file to a proper structure. The xml looks like this What shall I use? Does anybody has some example-code to share or some good links/book-references? thx for any reply -fe (5 Replies)
Discussion started by: bin-doph
5 Replies
Login or Register to Ask a Question