awk - Split an xml file into 2 halves in perl -
i have xml file in below format:
<installer> <plugins> . . . </plugins> </installer> <installer> <plugins> . . . </plugins> </installer>
so, can see there 2 parts here i.e. 2 installer blocks. want segregate , redirect first installers part test1.xml file , second installers part test2.xml.
i know achieve same using loop. but, please provide me solution using sed/awk faster processing.
please please don't use regular expression or line based approach splitting xml. way lies brittle code , broken xml, , that's bad news concerned.
using xml posted in previous question reference point:
#!/usr/bin/perl use strict; use warnings; use xml::twig; use data::dumper; $file_extn = 1; sub split_installer { ( $twig, $installer ) = @_; open ( $output, ">", "test".$file_extn++.".xml" ) or warn !; print {$ouput} $installer -> sprint(); close ( $output ); } $twig = xml::twig -> new ( twig_handlers => { 'installer' => \&split_installer } ) -> parsefile ( 'your_file.xml );
a lot of accomplished utility xml_split
.
Comments
Post a Comment