From: Jason Etheridge Date: Tue, 4 Dec 2018 17:23:47 +0000 (-0500) Subject: tool to spit out records that contain the tag/subfield/value combination provided X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=commitdiff_plain;h=76e0f557b6ca6e2ad64d435c9f62ee9028a16768 tool to spit out records that contain the tag/subfield/value combination provided --- diff --git a/bibs_items/marc_grep.pl b/bibs_items/marc_grep.pl new file mode 100755 index 0000000..bdd7dc8 --- /dev/null +++ b/bibs_items/marc_grep.pl @@ -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(); + } +}