insert lines feeds in XML document (225 Views)
Reply
Occasional Contributor
Delvaux Ulrich
Posts: 7
Registered: ‎02-21-2002
Message 1 of 7 (225 Views)

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
Please use plain text.
Honored Contributor
harry d brown jr
Posts: 8,418
Registered: ‎12-12-2000
Message 2 of 7 (225 Views)

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
Please use plain text.
Occasional Contributor
Delvaux Ulrich
Posts: 7
Registered: ‎02-21-2002
Message 3 of 7 (225 Views)

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?
Please use plain text.
Honored Contributor
harry d brown jr
Posts: 8,418
Registered: ‎12-12-2000
Message 4 of 7 (225 Views)

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
Please use plain text.
Occasional Contributor
Delvaux Ulrich
Posts: 7
Registered: ‎02-21-2002
Message 5 of 7 (225 Views)

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?

Please use plain text.
Honored Contributor
harry d brown jr
Posts: 8,418
Registered: ‎12-12-2000
Message 6 of 7 (225 Views)

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
Please use plain text.
Occasional Contributor
Delvaux Ulrich
Posts: 7
Registered: ‎02-21-2002
Message 7 of 7 (225 Views)

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
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation