3 # Copyright 2009-2016, Equinox Software, Inc.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # Take a file that starts off like this:
21 # <?xml version="1.0" encoding="UTF-8" ?>
22 # <DestinyCustomReport>
27 # cat file | xml2 | cut -f4- -d/ > file.munged
29 # And feed the results to this script to create a .tsv version of the data.
31 # destiny_xml_to_tsv.pl file.munged > file.munged.tsv
45 # print STDERR "Loaded this line: " . $_;
47 # Is this the start of a new record?
51 print STDERR "Processing record $serial.\n";
55 # If this isn't the start of the new record, it's a new line in the present record.
58 # Looks like we've got some actual data! Let's store it.
59 # FIXME: For large batches of data, we may run out of memory and should store this on disk.
60 if ( /^(.*?)=(.*)$/ ) {
63 $unique_fields{$field} = 1;
64 $records[$serial]{$field} = $2;
66 print STDERR "Data extracted: \$records[$serial]{'$field'} = '$2'\n";
71 # This is the continuation of the previous line.
74 $records[$serial]{$field} .= ' ' . $_;
75 print STDERR "Appended data to previous field. \$records[$serial]{'$field'} is now '" . $records[$serial]{$field} . "'.\n";
80 print STDERR "Loaded " . scalar(@records) . " records.\n";
85 @sorted_fields = sort keys %unique_fields;
86 foreach $i (@sorted_fields) {
93 for (my $u = 0; $u < @records; $u++) {
95 foreach $f (@sorted_fields) {
96 if (defined $records[$u]{$f}) {
97 print $records[$u]{$f};
104 print STDERR "Wrote " . scalar(@records) . " records.\n";
105 # uh-bdee-uh-bdee-uh-bdee-uh- THAT'S ALL, FOLKS