From 76e0f557b6ca6e2ad64d435c9f62ee9028a16768 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Tue, 4 Dec 2018 12:23:47 -0500 Subject: [PATCH 1/1] tool to spit out records that contain the tag/subfield/value combination provided --- bibs_items/marc_grep.pl | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) create mode 100755 bibs_items/marc_grep.pl 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(); + } +} -- 1.7.2.5