tool to spit out records that contain the tag/subfield/value combination provided
[migration-tools.git] / bibs_items / marc_grep.pl
1 #!/usr/bin/perl -w
2 # ./marc_grep.pl tag subfield value marcfile > out 2> err
3 # Spit out records that contain the tag/subfield/value combination provided
4
5 use strict;
6 use warnings;
7
8 use MARC::Batch;
9
10 my ($tag,$subfield,$value,$file) = @ARGV;
11
12 my $batch = MARC::Batch->new( 'USMARC', $file );
13 $batch->strict_off();
14 $batch->warnings_off();
15
16
17 while ( my $marc = $batch->next ) {
18     my $found_match = 0;
19     foreach my $f ($marc->fields()) {
20         if ($f->tag() eq $tag && $f->subfield($subfield) eq $value) {
21             $found_match = 1;
22         }
23     }
24     if ($found_match) {
25         print $marc->as_usmarc();
26     }
27 }