From: Jason Etheridge Date: Tue, 1 Oct 2019 16:15:17 +0000 (-0400) Subject: with Koha, you don't want to batch import authorities that have their own 001 X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=commitdiff_plain;h=2cbcec09ac6b22982fd5abfe08cc79f7209710af with Koha, you don't want to batch import authorities that have their own 001 --- diff --git a/munge_001_003_035.pl b/munge_001_003_035.pl new file mode 100644 index 0000000..8dceb7d --- /dev/null +++ b/munge_001_003_035.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl -w +use strict; + +use MARC::File::USMARC; + +my $file = MARC::File::USMARC->in( $ARGV[0] ); +while ( my $marc = $file->next() ) { + my @cns = $marc->field('001'); # grabs all of them + my $cn = $marc->field('001')->data(); # grabs the first + $marc->delete_fields(@cns); # deletes all of them + my @sources = $marc->field('003'); # etc + my $source = $marc->field('003')->data(); + $marc->delete_fields(@sources); + my @tags035 = $marc->field('035'); + my $tag035 = $marc->field('035'); + my $tag035a = defined $tag035 ? $tag035->subfield('a') : undef; + $marc->delete_fields(@tags035); + if (defined $cn) { + my @arr = ( + '035','','','a' + + ); + if (defined $source) { + push @arr, "($source) $cn"; + } else { + push @arr, "$cn"; + } + if (defined $tag035a) { + push @arr, 'z'; + push @arr, $tag035a; + } + my $new035 = MARC::Field->new(@arr); + $marc->insert_fields_ordered($new035); + } + print $marc->as_usmarc(); +} +$file->close(); +undef $file; +