with Koha, you don't want to batch import authorities that have their own 001
authorJason Etheridge <jason@equinoxinitiative.org>
Tue, 1 Oct 2019 16:15:17 +0000 (12:15 -0400)
committerJason Etheridge <jason@equinoxinitiative.org>
Tue, 1 Oct 2019 16:15:17 +0000 (12:15 -0400)
munge_001_003_035.pl [new file with mode: 0644]

diff --git a/munge_001_003_035.pl b/munge_001_003_035.pl
new file mode 100644 (file)
index 0000000..8dceb7d
--- /dev/null
@@ -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;
+