Visit Our UNIX and Linux User Community


How to enter a newline after every XML tag end?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to enter a newline after every XML tag end?
# 1  
Old 08-05-2009
Error How to enter a newline after every XML tag end?

Hi Guyz,

I have an XML message in following format:
Quote:
<ABC>Hello</ABC><BCD>How r u?</BCD><CDE>GOD Bless u</CDE>
I want my contents to be formatted in following order:
Quote:
<ABC>Hello</ABC>
<BCD>How r u?</BCD>
<CDE>GOD Bless u</CDE>
i.e. I want a newline after every XML tag end.
How to do this?

Thnx in advance.
# 2  
Old 08-05-2009
Code:
echo '<ABC>Hello</ABC><BCD>How r u?</BCD><CDE>GOD Bless u</CDE>' |sed 's/<\/[^>]*>/&\n/g'

# 3  
Old 08-05-2009
Code:
echo '<ABC>Hello</ABC><BCD>How r u?</BCD><CDE>GOD Bless u</CDE>' |sed 's/<\/[^>]*>/&\n/g'

Oops! it gave me alphabet n after every tag end.

I tried following:
Code:
echo '<ABC>Hello</ABC><BCD>How r u?</BCD><CDE>GOD Bless u</CDE>' |sed 's/<\/[^>]*>/&/\n/g'

I also tried:
Code:
echo '<ABC>Hello</ABC><BCD>How r u?</BCD><CDE>GOD Bless u</CDE>' |sed 's/<\/[^>]*>/&\\n/g'

But, it gave me '\n' after every tag end.

Last edited by DTechBuddy; 08-05-2009 at 09:48 AM..
# 4  
Old 08-05-2009
Code:
# echo '<ABC>Hello</ABC><BCD>How r u?</BCD><CDE>GOD Bless u</CDE>' |sed 's/<\/[^>]*>/&\
/g'

# 5  
Old 08-05-2009
Code:
$
$ echo "<ABC>Hello</ABC><BCD>How r u?</BCD><CDE>GOD Bless u</CDE>" | perl -ne 's/(<\/\w+>)/$1\n/g; print'
<ABC>Hello</ABC>
<BCD>How r u?</BCD>
<CDE>GOD Bless u</CDE>
 
$

tyler_durden
# 6  
Old 08-06-2009
Hi Guyz,
Both the codes worked.

Thnx a lot. Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #61
Difficulty: Easy
A computer on a LAN segment is uniquely identified by its MAC address.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grepping multiple XML tag results from XML file.

I want to write a one line script that outputs the result of multiple xml tags from a XML file. For example I have a XML file which has below XML tags in the file: <EMAIL>***</EMAIL> <CUSTOMER_ID>****</CUSTOMER_ID> <BRANDID>***</BRANDID> Now I want to grep the values of all these specified... (1 Reply)
Discussion started by: shubh752
1 Replies

2. Shell Programming and Scripting

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies

3. UNIX for Dummies Questions & Answers

Enter carriage return in xml file after each tag (> sign)

I have an xml file which is generated in a single line an looks like this <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><Batch_Id="1999996" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><some data....><some data....>closing lines...... I need to have a separate line... (3 Replies)
Discussion started by: vx04
3 Replies

4. Shell Programming and Scripting

To search for a particular tag in xml and collate all similar tag values and display them count

I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help File: <xml><object1>house</object1><object2>child</object2>... (9 Replies)
Discussion started by: srkmish
9 Replies

5. Shell Programming and Scripting

XML Parse between to tag with upper tag

Hi Guys Here is my Input : <?xml version="1.0" encoding="UTF-8"?> <xn:MeContext id="01736"> <xn:VsDataContainer id="01736"> <xn:attributes> <xn:vsDataType>vsDataMeContext</xn:vsDataType> ... (12 Replies)
Discussion started by: pareshkp
12 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

How to retrieve the value from XML tag whose end tag is in next line

Hi All, Find the following code: <Universal>D38x82j1JJ </Universal> I want to retrieve the value of <Universal> tag as below: Please help me. (3 Replies)
Discussion started by: mjavalkar
3 Replies

8. Shell Programming and Scripting

XML tag replacement from different XML file

We have 2 XML file 1. ORIGINAL.xml file and 2. ATTRIBUTE.xml files, In the ORIGINAL.xml we need some modification as <resourceCode>431048</resourceCode>under <item type="Manufactured"> tag - we need to grab the 431048 value from tag and pass it to database table in unix shell script to find the... (0 Replies)
Discussion started by: balrajg
0 Replies

9. Shell Programming and Scripting

how to find the end tag in xml file.

Hi, I am newbie. I wanted to know how to find the end tag in shell where I have multiple tags in xml like <tag name="x" version="1.0"> </tag> <tag name="x" version="1.0"> </tag> <tag name="x" version="1.0"> </tag> And I wanted to update depends this xml as (in side the tag <subtag ... (10 Replies)
Discussion started by: mariakumar3
10 Replies

10. UNIX for Dummies Questions & Answers

Enter data at end of a file

Hi All, I have a sample datafile: 5.1 5.2 0.8 6.1 What I want to do is create an additional 3 rows with the number "0.7". so that I now have: 5.1 5.2 0.8 6.1 0.7 0.7 (3 Replies)
Discussion started by: tintin72
3 Replies

Featured Tech Videos