3 # Copyright 2009-2012, 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.
22 use XBase; # or could use DBI and DBD::XBase;
30 GetOptions('in=s' => \$in, 'out=s' => \$out, 'help' => \$help);
32 if ($help) { &show_help; }
35 if ($in eq '') { push @errors, 'Input file must be specified ( --in inputfile.dbf )' };
36 if ($out eq '') { push @errors, 'Output file must be specified ( --out outputfile.tsv )' };
37 if (@errors > 0) { &show_help (@errors); }
39 open OUT, ">$out" or die $!;
41 my $table = new XBase $in or die XBase->errstr;
43 # get list of field names
44 my @names = $table->field_names;
46 # print a header line with field names
47 print OUT join ("\t", @names) . "\n";
55 Encode::encode("utf8", $_)
56 } else { ''; } # to avoid 'Use of uninitialized value in join'
60 for (0 .. $table->last_record) {
62 my ($deleted, @row) = $table->get_record($_);
63 @row = map (&clean, @row);
64 print OUT join("\t", @row) . "\n" unless $deleted;
68 print STDERR "$i records exported to $out.\n";
73 print "\nERROR - $msg\n" if $msg;
76 dbf2tsv - convert XBase DBF to tab-separated format
80 * Escapes backslash, newline, carriage return, and tab characters.
85 dbf2tsv --in inputfile.dbf --out outputfile.tsv
95 dbf2tsv - convert XBase DBF to tab-separated values
99 dbf2tsv --in inputfile.dbf --out outputfile.dbf
103 Munges data in the following ways:
105 * Escapes backslash, newline, carriage return, and tab characters.