more gooder working?
[migration-tools.git] / extract_loadset
old mode 100644 (file)
new mode 100755 (executable)
index 9b0be3c..a4f41ac
@@ -8,12 +8,24 @@ use Getopt::Long;
 my $conf  = {}; # configuration hashref
 initialize($conf);
 
-open FP, '<', shift or die "Can't open input file: $!\n";
-
+# build exclusion hash
+open FP, '<', shift or die "Can't open matchset file: $!\n";
+my %exclude = ();
 while (<FP>) {
+    my ($lead,$sub) = split /\t/;
+    $exclude{$sub}  = 1 unless ($sub < $conf->{lowerbound});
+}
+close FP;
 
+# strip exclusions from marcxml file
+open MI, '<', $conf->{marc} or die "Can't open input file: $!\n";
+open MO, '>', $conf->{output} or die "Can't open output file: $!\n";
+while (<MI>) {
+    m/tag="$conf->{tag}",+?<subfield code="$conf->{subfield}">(\d+)</;
+    print MO unless $exclude{$1};
 }
 
+
 sub initialize {
     my ($c) = @_;
     my @missing = ();
@@ -22,15 +34,22 @@ sub initialize {
     binmode(STDIN, ':utf8');
 
     my $rc = GetOptions( $c,
-                         'prefix|p=s',
+                         'lowerbound|l=i',
+                         'input|i=s',
+                         'output|o=s',
+                         'tag|t=i',
+                         'subfield|s=s',
                          'help|h',
                        );
     show_help() unless $rc;
     show_help() if ($c->{help});
 
+    $conf->{tag} = $conf->{tag} || 903;
+    $conf->{subfield} = $conf->{subfield} || 'a';
+
     my @keys = keys %{$c};
     show_help() unless (@ARGV and @keys);
-    for my $key ('prefix')
+    for my $key ('output', 'lowerbound', 'input')
       { push @missing, $key unless $c->{$key} }
     if (@missing) {
         print "Required option: ", join(', ', @missing), " missing!\n";
@@ -40,7 +59,13 @@ sub initialize {
 
 sub show_help {
     print <<HELP;
-Usage is: compress_fingerprints -p PREFIX INPUTFILE
+Usage is: extract_loadset -l BOUND -i INPUTXML -o OUTPUTXML MATCHSET
+
+  --lowerbound  -l  Lowest record ID which will be included in the loadset
+  --input       -i  MARCXML input file
+  --output      -o  MARCXML output file
+  --tag         -t  MARC tag to use as identifier (default: 903)
+  --subfield    -s  Subfield of --tag argument (default: 'a')
 HELP
 exit;
 }