tool to spit out records that contain the tag/subfield/value combination provided
authorJason Etheridge <jason@equinoxinitiative.org>
Tue, 4 Dec 2018 17:23:47 +0000 (12:23 -0500)
committerJason Etheridge <jason@equinoxinitiative.org>
Tue, 4 Dec 2018 17:23:47 +0000 (12:23 -0500)
bibs_items/marc_grep.pl [new file with mode: 0755]

diff --git a/bibs_items/marc_grep.pl b/bibs_items/marc_grep.pl
new file mode 100755 (executable)
index 0000000..bdd7dc8
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/perl -w
+# ./marc_grep.pl tag subfield value marcfile > out 2> err
+# Spit out records that contain the tag/subfield/value combination provided
+
+use strict;
+use warnings;
+
+use MARC::Batch;
+
+my ($tag,$subfield,$value,$file) = @ARGV;
+
+my $batch = MARC::Batch->new( 'USMARC', $file );
+$batch->strict_off();
+$batch->warnings_off();
+
+
+while ( my $marc = $batch->next ) {
+    my $found_match = 0;
+    foreach my $f ($marc->fields()) {
+        if ($f->tag() eq $tag && $f->subfield($subfield) eq $value) {
+            $found_match = 1;
+        }
+    }
+    if ($found_match) {
+        print $marc->as_usmarc();
+    }
+}