BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

insert lines feeds in XML document

Highlighted
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
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
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?
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
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?

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
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