Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ cat file_<ID>.xml
- ...
- ...
- ...
- <double>1.2342</double>
- <double>2.3456</double>
- ...
- ...
- ...
- ...
- file_0001 1.2342 2.3456 ...
- file_0002 1.2342 2.3456 ...
- ./from_xml_to_csv.sh 100.45s user 94.84s system 239% cpu 1:21.48 total
- find . ! -name . -prune -name pattern -type f -exec cat {} + | ...
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use XML::Twig;
- my $twig = XML::Twig -> new;
- $twig -> parse ( *DATA );
- foreach my $double ( $twig -> get_xpath('//double') ) {
- print $double -> trimmed_text,"n";
- }
- __DATA__
- <root>
- <subnode>
- <another_node>
- <double>1.2342</double>
- <double>2.3456</double>
- <some_other_tag>fish</some_other_tag>
- </another_node>
- </subnode>
- </root>
- 1.2342
- 2.3456
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use XML::Twig;
- use Text::CSV;
- my $twig = XML::Twig->new;
- my $csv = Text::CSV->new;
- #open our results file
- open( my $output, ">", "results.csv" ) or die $!;
- #iterate each XML File.
- foreach my $filename ( glob("/path/to/xml/*.xml") ) {
- #parse it
- $twig->parsefile($filename);
- #extract all the text of all the 'double' elements.
- my @doubles = map { $_->trimmed_text } $twig->get_xpath('//double');
- #print it as comma separated.
- $csv->print( $output, [ $filename, @doubles ] );
- }
- close($output);
- get_xpath("/root/subnode/another_node/double")
- for f in `ls *.xml` ;
- do
- echo $f,`grep double $f | awk -F '[<>]' '{print $3}' | tr 'n' ','`;
- done
Add Comment
Please, Sign In to add comment