Line Break Issue in XML file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Line Break Issue in XML file
# 1  
Old 12-12-2012
Line Break Issue in XML file

Hi Experts,
Kindly help me to resole the line break issue mentioned below sample xml file:

sample source File:
==============
Code:
<?!New XML File><NEWRECORDS xmlns xsi:ABCD.xsd><HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO><HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO><HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO><HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO><HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO></NEWRECORDS>

Expected Output:
===============
Code:
<?!New XML File>
<NEWRECORD xmlns xsi: ABCD.xsd>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
</NEWRECORD>

Note: along with the first 2-lines and last line, each <HALLO> record is expecting in every line.

Regards
UnniVKN

Last edited by Franklin52; 12-12-2012 at 05:52 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 12-12-2012
Code:
$ perl -pe 's/File>/File>\n/;s/xsd>/xsd>\n/;s/\/HALLO>/\/HALLO>\n/g;' input.xml
<?!New XML File>
<NEWRECORDS xmlns xsi:ABCD.xsd>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
</NEWRECORDS>

# 3  
Old 12-12-2012
Please use code tags for code and data sample..

Code:
$ sed 's/<HALLO>/\n&/;s/<\/HALLO>/&\n/g;s/New XML File>/&\n/g;' file
<?!New XML File>
<NEWRECORDS xmlns xsi:ABCD.xsd>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
<HALLO><VT>123</VT><NT>456</NT><PH>987654357</PH></HALLO>
</NEWRECORDS>

# 4  
Old 12-13-2012
Hi itkamaraj & pamu,

Thanks a lot for your valuable time & effort. I have tested the code & it is working fine. Keep it up your good work. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue splitting file based on XML tags

more a-d.txt1 <a-dets> <a-serv> <aserv>mymac14,mymac15:MYAPP:mydom:/web/domain/mydom/config <NMGR>:MYAPP:/web/bea_apps/perf/NMGR/NMGR1034 <a-rep-string> 11.12.10.01=192.10.00.26 10.20.18.10=192.10.00.27 </a-rep-string> </a-serv> <w-serv>... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. UNIX for Dummies Questions & Answers

add a string to a file without line break

I searched and found "echo -n" and "printf" are solution for this, but they are not here: $ echo "hello" >> test $ cat test hello $ echo -n "world" >> test $ cat test hello world $ echo -n " seriously?" >> test $ cat test hello world seriously? This is not successful... (15 Replies)
Discussion started by: stunn3r
15 Replies

3. Shell Programming and Scripting

how do I break line in a file when a pattern is matched ?

Hi All, I am stuck for quite sometime now. Below is a line in my file - GS|ED|001075|001081|20110626|1806|100803|X|004010ST|130|100803001 This line occurs only once and it is the second line. I have to break this line into two lines from ST (bold) such that it looks like -... (5 Replies)
Discussion started by: ihussain
5 Replies

4. Shell Programming and Scripting

[Solved] Line Break Issue for an XML file

I got an XML file(file name TABLE.xml) which the data format has line breaks(with no Spaces, no Nulls, no characters between each line), I need to write a KSH script which gives me the data in single line as format shown below My input file which have line breaks: <TABLE> <TABLE-ROW> <S_NO>... (7 Replies)
Discussion started by: pred55
7 Replies

5. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

6. Shell Programming and Scripting

BASH: Break line, read, break again, read again...

...when the lines use both a colon and commas to separate the parts you want read as information. The first version of this script used cut and other non-Bash-builtins, frequently, which made it nice and zippy with little more than average processor load in GNOME Terminal but, predictably, slow... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

7. Shell Programming and Scripting

How to remove line break character in a file

Hi, we are trying to process a csv file,in which we are getting data with line breaks.How to remove the line break character in the file? when i try to print the line break charcter using od -c,it gives as '\n' character for both line break and line feed. Please provide your valuable... (6 Replies)
Discussion started by: cnraja
6 Replies

8. Shell Programming and Scripting

How to remove line break in a csv file

Hi Experts, My requirement is to read the csv file and need to remove if any line break in it. sample data: Row1: "Oslo, Symra kino",Oslo,130-7,Symra 1,130-7-91 Row2:"Tønsberg, Brygga Kino SF",Tønsberg,202-1, Tønsberg SF 4,202-1-4 Expected data: Row1: "Oslo, Symra... (6 Replies)
Discussion started by: cnraja
6 Replies

9. Shell Programming and Scripting

How to filter only comments while reading a file including line break characters.

How do I filter only comments and still keep Line breaks at the end of the line!? This is one of the common tasks we all do,, How can we do this in a right way..!? I try to ignore empty lines and commented lines using following approach. test.sh # \040 --> SPACE character octal... (17 Replies)
Discussion started by: kchinnam
17 Replies

10. Shell Programming and Scripting

Replacing characters in file with line break

Hi, Apologies if this has been asked before, but I searched and was not able to find an answer. It's probably a simple question to answer for those of you with some experience, though... I have a relatively long string where tokens are separated by the colon (':') character. Let's say the... (10 Replies)
Discussion started by: johnemb
10 Replies
Login or Register to Ask a Question