#!/usr/bin/perl # rename.pl - given two files of MARC records, extract the identifiers in one and rename the identifiers in the other # Eric Lease Morgan # April 5, 2016 - first cut # require use MARC::Batch; use strict; # sanity check my $original = $ARGV[ 0 ]; my $new = $ARGV[ 1 ]; if ( ! $new or ! $original ) { print "Usage: $0 \n"; exit; } # initialize my %identifiers = (); binmode(STDOUT, ":utf8"); # process each record in the new file storing the result in a hash my $batch = MARC::Batch->new( 'USMARC', $new ); while ( my $record = $batch->next ) { # local identifier $identifiers{ $record->field( '001' )->as_string }++ } # process each record in the original file my $batch = MARC::Batch->new( 'USMARC', $original ); while ( my $record = $batch->next ) { # get the identifier my $identifier = $record->field( '001' )->as_string; # check to see if the current identifier is in the previously created list if ( $identifiers{ $identifier } ) { # munge the identifier $record->field( '001' )->update( 'x-' . $identifier ); } # output print $record->as_usmarc; } # done exit;