Help in removing xml tags


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in removing xml tags
# 1  
Old 06-04-2009
Help in removing xml tags

Hi,

I have a input xml file like this

<postalAddress:>379 PROSPECT ST </postalAddress:>
<street:>STE B </street:>
<l:>TORRINGTON </l:>
<st:>CT</st:>
<postalCode:>067905238</postalCode:>
<telephoneNumber:>9999999999</telephoneNumber:>
<facsimileTelephoneNumber:>9999999999</facsimileTelephoneNumber:>

<postalAddress:>579 RARITAN RD </postalAddress:>
<street:>STE A </street:>
<l:>ROSELLE </l:>
<st:>NJ</st:>
<postalCode:>072039999</postalCode:>
<telephoneNumber:>9999999999</telephoneNumber:>
<facsimileTelephoneNumber:>9999999999</facsimileTelephoneNumber:>


and I need my ouput to be


postalAddress:379 PROSPECT ST
street:STE B
l:TORRINGTON
st:CT
postalCode:067905238
telephoneNumber:9999999999
facsimileTelephoneNumber:9999999999

postalAddress:579 RARITAN RD
street:STE A
l:ROSELLE
st:NJ
postalCode:072039999
telephoneNumber:9999999999
facsimileTelephoneNumber:9999999999
# 2  
Old 06-04-2009
Not the most elegant of code but it does what you wnat:
Code:
$ cat address.xml
<postalAddress:>379 PROSPECT ST </postalAddress:>
<street:>STE B </street:>
<l:>TORRINGTON </l:>
<st:>CT</st:>
<postalCode:>067905238</postalCode:>
<telephoneNumber:>9999999999</telephoneNumber:>
<facsimileTelephoneNumber:>9999999999</facsimileTelephoneNumber:>
$ cat ./gettextfromxml.sh
#!/bin/bash

awk -F"<" '{ print $2 }' address.xml | sed -e 's/>//'
$ ./gettextfromxml.sh
postalAddress:379 PROSPECT ST 
street:STE B 
l:TORRINGTON 
st:CT
postalCode:067905238
telephoneNumber:9999999999
facsimileTelephoneNumber:9999999999
$

# 3  
Old 06-04-2009
Quote:
Originally Posted by TonyFullerMalv
Not the most elegant of code but it does what
awk -F"<" '{ print $2 }' address.xml | sed -e 's/>//'
[/code]
just one awk command will do. you can do substitution in awk using either gsub or sub.
# 4  
Old 06-04-2009
It can also be done using a sed oneliner i.e.
Code:
sed -n 's/<\(.*:\)>\([[:print:]][^<]*\).*$/\1\2/p' file

# 5  
Old 06-04-2009
Quote:
Originally Posted by TonyFullerMalv
Code:
#!/bin/bash

awk -F"<" '{ print $2 }' address.xml | sed -e 's/>//'

Just awk Smilie
Code:
awk -F'[<|>]' '{print $2,$3}' file

# 6  
Old 06-05-2009
Code:
sed 's/<\([^>]*\)>\(.*\)<\/\1>/\1\2/' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pull multiple XML tags from the same XML file in Shell.?

I'm searching for the names of a TV show in the XML file I've attached at the end of this post. What I'm trying to do now is pull out/list the data from each of the <SeriesName> tags throughout the document. Currently, I'm only able to get data the first instance of that XML field using the... (9 Replies)
Discussion started by: hungryd
9 Replies

2. Shell Programming and Scripting

Removing LF from specific line in XML

Hello Guys, I have an XML file with below sample (just one data record is given below), I am getting LF characters as mentioned in below specific lines. I need to remove those. When I tried, it is removing from complete file instead of those two specific lines. And to add one LF after one... (2 Replies)
Discussion started by: karumudi7
2 Replies

3. Shell Programming and Scripting

How to add Xml tags to an existing xml using shell or awk?

Hi , I have a below xml: <ns:Body> <ns:result> <Date Month="June" Day="Monday:/> </ns:result> </ns:Body> i have a lookup abc.txtt text file with below details Month June July August Day Monday Tuesday Wednesday I need a output xml with below tags <ns:Body> <ns:result>... (2 Replies)
Discussion started by: Nevergivup
2 Replies

4. Shell Programming and Scripting

Compare two xml files while ignoring some xml tags

I've got two different files and want to compare them. File 1 : <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record id="38,557"><columns><column><name>orge... (2 Replies)
Discussion started by: Shaishav Shah
2 Replies

5. Shell Programming and Scripting

Shell Command to compare two xml lines while ignoring xml tags

I've got two different files and want to compare them. File 1 : HTML Code: <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record... (1 Reply)
Discussion started by: Shaishav Shah
1 Replies

6. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

7. Shell Programming and Scripting

Removing unwanted tags from xml file

I have a XML file given as below: "<ProductUOMAlternativeDetails> <removetag> <UOMCode>EA</UOMCode> <numeratorForConversionToBaseUOM>1</numeratorForConversionToBaseUOM> <denominatorForConversionToBaseUOM>1</denominatorForConversionToBaseUOM> <length>0.59</length> <width>0.96</width> ... (3 Replies)
Discussion started by: vikingh
3 Replies

8. Shell Programming and Scripting

removing empty tags

Hi, I have a file as shown below. <crown:clinicalData> <crown:alb date="2008-07-10" lowValue="3.50" method="BCG" value="3.50"/> <crown:cre date="2008-07-10" value="9.5"></crown:cre> <crown:ktvHdAd> </crown:ktvHdAd> <crown:ktvPdAd> </crown:ktvPdAd> ... (1 Reply)
Discussion started by: vijayhai
1 Replies

9. UNIX for Dummies Questions & Answers

Removing spaces between XML tags<XX XX> -> <XXXX>

hey guys, i have an XML like this: <documents> <document> <Object ID>100114699999</Object ID> <Object Create Date Time>2008-04-07T00:00:00</Object Create Date Time> </document> <documents> I need all my tags within the XML to not include any spaces. i.e. everything between <t a g> in... (8 Replies)
Discussion started by: sharoff
8 Replies

10. UNIX for Dummies Questions & Answers

Removing leading and trailing spaces of data between the tags in xml.

I am having xml document as below. <transactionid> 00 </transactionid> <tracknumber> 0 </tracknumber> <key> N/A </key> But the data contains leading and trailing spaces between the tags. Please let me know how can i remove these leading and trailing spaces between the tags.... (2 Replies)
Discussion started by: jhmr7
2 Replies
Login or Register to Ask a Question