in reply to Pipe dream
for each table of each file. But the problem was that some tables did have spaces in the name, then it was starting to be harder to do on plain shell, because it was splitting each part of the name of the table and using as a single name... So I decided to do it in Perl, and ended with the following code.mdb-export -d , file.mdb tablename | gzip -9 -c > file.csv.gz
This code uses the pipes just like the shell would use... I was thinking in creating a module to make it easier to chain pipes like this, but, hmmmm... I'm not sure if it's a good idea...use IPC::Open2; use strict; opendir DIR, "."; my @bancos = grep { /.mdb$/ } readdir DIR; closedir DIR; foreach my $db (@bancos) { chomp $db; print "$db\n"; open TABLES, "mdb-tables -1 $db |" || die $!; my @tables = <TABLES>; close TABLES; my $dbdir = $db; $dbdir =~ s/\.mdb$//; mkdir $dbdir || die $!; foreach my $table (@tables) { chomp $table; open('MDBEXPOUT', "mdb-export -d , '$db' '$table' |") +|| die $!; $table =~ s/\W/_/g; open('OUTFILE', ">$dbdir/$table.csv.gz") || die $!; open2('>&OUTFILE', '<&MDBEXPOUT', "gzip", "-9", "-c") +|| die $!; wait; close MDBEXPOUT; close OUTFILE; print "$dbdir/$table\n"; } }
|
|---|