-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifyMarc.pl
86 lines (63 loc) · 1.54 KB
/
modifyMarc.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!C:/Perl/bin/perl -w
use strict;
use IO::File;
use utf8;
use Encode;
use Data::Dumper;
use File::Slurp;
##
# Slurp in identifier file
#
my $identifier_file = read_file(shift(@ARGV));
##
# Open file for output
#
my $outputfile = "hathiSubmission".$ARGV[0];
my $fh = IO::File->new($outputfile, 'w')
or die "unable to open output file for writing: $!";
binmode($fh, ':utf8');
##
#change PERL default record delimiter
#
$/="\n\n";
##
#create a hash of MARC records; sys no is key
#
my %records_hash;
while (<>) #here, ARGV is the MARC file
{
chomp;
$_ = decode_utf8( $_ );
$_ =~/=001 (\d*)\n/; ##get sys no from MARC record
my $sysno=$1;
#print "$1\n";
$records_hash{$sysno}=$_;
}
#print Dumper(\%records_hash);
##
# process identifiers add 955 field to records
#
my @identifier_file= split('\n', $identifier_file);
foreach (@identifier_file)
{
my @identifier=split('\t',$_);
$fh->print("$records_hash{$identifier[0]}");
if ($identifier[3])
{
$fh->print("\n=955 \\\\\$b$identifier[2]\$q$identifier[1]\$v$identifier[3]");
}
else
{
$fh->print("\n=955 \\\\\$b$identifier[2]\$q$identifier[1]");
}
$fh->print("\n\n");
}
#Close output file
$fh->close();
=pod
use: modifyMarc.pl hathiData.txt records.mrk
hathiData.txt is a tab-delimited file downloaded from the Internet Archive containing the following in each row: ALMA sys no, book id, ark id, url, volume, title.
records.mrk
Outputs a file with 'url' prefixed to the name of the original .mrk file.
[email protected] May 21, 2013
=cut