extract just documents which have files
[koha-eprints] / tsv2eprints.pl
index 62e7521..7535069 100755 (executable)
@@ -249,8 +249,11 @@ print qq{<?xml version="1.0" encoding="utf-8" ?>
 };
 
 
-open(my $tsv_fh,   '<:encoding(UTF-8)', "$koha_path.tsv");
-open(my $tsv_marc, '<:encoding(UTF-8)', "$koha_path.marc");
+open(my $tsv_fh,  '<:encoding(UTF-8)', "$koha_path.tsv");
+open(my $marc_fh, '<', "$koha_path.marc");
+open(my $import_fh, '>', "$koha_path.import.marc");
+
+my $last_offset = 0;
 
 while(<$tsv_fh>) {
        my $line = $_;
@@ -266,10 +269,18 @@ while(<$tsv_fh>) {
 
        if ( $item->{full_path} = $files->{$biblionumber} ) {
                $stat->{file}++;
+
+               seek $marc_fh, $last_offset, 0;
+               read $marc_fh, my $marc, $offset - $last_offset;
+               print $import_fh $marc;
+               warn "# marc $biblionumber $title\n";
+
        } else {
                $stat->{missing}++;
        }
 
+       $last_offset = $offset;
+
 }
 
 print qq{