turns out the inds in empty datafields won't ALWAYS be spaces
[migration-tools.git] / yaz-cleanup
1 #!/usr/bin/perl
2
3 open MARC, '<', 'incoming.marc.xml';
4 open NUMARC, '>', 'incoming.clean.marc.xml';
5
6 $line1 = <MARC>;
7
8 while ($line2 = <MARC>) {
9     if ($line1 =~ m/<datafield tag="..." ind1="." ind2=".">/) {
10         if ($line2 =~ m|</datafield>|) {
11             $line1 = <MARC>;
12             next;
13         }
14     }
15     $line1 =~ s/tag="  /tag="00/g;
16     $line1 =~ s/tag=" /tag="0/g;
17     $line1 =~ s/tag="-/tag="0/g;
18     $line1 =~ s/tag="(\d\d) /tag="0$1/g;
19     print NUMARC $line1;
20     $line1 = $line2;
21 }
22 print NUMARC $line1;