Operating System - HP-UX
1748270 Members
3903 Online
108760 Solutions
New Discussion юеВ

Re: insert lines feeds in XML document

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