Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

insert lines feeds in XML document

Highlighted
Delvaux Ulrich
Occasional Contributor

insert lines feeds in XML document

Hello,
I have an XML document with multiple tags but when I open it with notepad or vi there are only 2 lines. How could I (using sed or perl) add lines feeds / carriage returs in this files ? I tried:
sed "s/\/>/\n/g"
sed "s/\/>/^M/g"
but is doesn't work.

Best regards,
Ulrich Delvaux
6 REPLIES
harry d brown jr
Honored Contributor

Re: insert lines feeds in XML document

#!/usr/bin/perl
while () {
@madman=split(/^M/);
if ($#madman > 0) {
for ( $i=0; $i <=$#madman; $i++ ) {
$tmpline=$madman[$i];
chomp($tmpline);
printf("%s\n",$tmpline);
}
} else {
$tmpline=$_;
chomp($tmpline);
printf("%s\n",$tmpline);
}
}


live free or die
harry d brown jr
Live Free or Die
Delvaux Ulrich
Occasional Contributor

Re: insert lines feeds in XML document

Hello Harry,

I don't understand your code. I tried it out but it just repeats what I type. In general what I need to do is:

file in:
this is a test xxx on xxx how to xxx split

file out:
this is a test
on
how to
split

I don't see what the madman parameter means in the perl.

Can you help please?
harry d brown jr
Honored Contributor

Re: insert lines feeds in XML document

Name the perl program (say zapper as shown below), then

cat oldfile | ./zapper > newfile


live free or die
harry d brown jr
Live Free or Die
Delvaux Ulrich
Occasional Contributor

Re: insert lines feeds in XML document

Hello Harry,
I placed the code in toto.pl and executed:
cat test | ./toto.pl > testout

testout contains the same as test whatever I put in test. I still don't see what the madman thing does?

harry d brown jr
Honored Contributor

Re: insert lines feeds in XML document

Using "vi", edit toto.pl

go to this line: @madman=split(/^M/);

replace the ^M (it probably put two characters in your toto.pl instead of a ctrl-m) with \r to give:

@madman=split(/\r/);

live free or die
harry d brown jr
Live Free or Die
Delvaux Ulrich
Occasional Contributor

Re: insert lines feeds in XML document

Hi,

Now it works, thanks a lot. I also got following working:

perl -p -e 's/\/>/\r\n/g' ulli.XML > test

Ulrich