c1a05597276ea60b4871c709896700c35fb974ff
[migration-tools.git] / spit_tlc_marc_holdings.pl
1 #!/usr/bin/perl
2 use open ':utf8';
3 use MARC::Batch;
4 use MARC::File::XML ( BinaryEncoding => 'utf-8' );
5 use MARC::Field;
6 use Unicode::Normalize;
7
8 my $count = 0;
9
10 binmode(STDOUT, ':utf8');
11 binmode(STDIN, ':utf8');
12
13 print join("\t",
14         "bib id",
15         "collection code",
16         "prefix",
17         "call number",
18         "cutter number",
19         "barcode",
20         "serial year",
21         "volume number",
22         "part subdivision 1",
23         "part subdivision 2",
24         "part subdivision 3",
25         "part subdivision 4",
26         "copy number",
27         "accession number",
28         "price",
29         "condition",
30         "magnetic media",
31         "checkin-in/check-out note"
32 ) . "\n";
33
34 foreach my $argnum ( 0 .. $#ARGV ) {
35
36         print STDERR "Processing " . $ARGV[$argnum] . "\n";
37
38     my $M;
39     open $M, '<:utf8', $ARGV[$argnum];
40     my $batch = MARC::Batch->new('XML',$M);
41
42         $batch->strict_off();
43         $batch->warnings_off();
44
45         while ( my $record = $batch->next() ) {
46
47         $count++;
48
49                 print STDERR "WARNINGS: Record $count : " .  join(":",@warnings) . " : continuing...\n" if ( @warnings );
50         my $my_903a = $record->field('903')->subfield('a'); # target bib id's here
51         my @tags = $record->field('949');
52         foreach my $tag ( @tags ) {
53             print join("\t",
54                 $my_903a, # bib id
55                 $tag->subfield('a') || '', # collection code
56                 $tag->subfield('b') || '', # prefix
57                 $tag->subfield('c') || '', # call number
58                 $tag->subfield('d') || '', # cutter number
59                 $tag->subfield('g') || '', # barcode
60                 $tag->subfield('h') || '', # serial year
61                 $tag->subfield('i') || '', # volume number
62                 $tag->subfield('j') || '', # part subdivision 1
63                 $tag->subfield('k') || '', # part subdivision 2
64                 $tag->subfield('l') || '', # part subdivision 3
65                 $tag->subfield('m') || '', # part subdivision 4
66                 $tag->subfield('n') || '', # copy number
67                 $tag->subfield('o') || '', # accession number
68                 $tag->subfield('p') || '', # price
69                 $tag->subfield('q') || '', # condition
70                 $tag->subfield('5') || '', # magnetic media 
71                 $tag->subfield('7') || '' # checkin-in/check-out note
72             ) . "\n";
73         }
74
75         }
76         print STDERR "Processed $count records\n";
77 }