toward better name parsing (handles names like "Van Horn, Fiona")
[migration-tools.git] / munge_marc_export_for_fingerprint.pl
1 #!/usr/bin/perl
2
3 # Copyright 2009-2012, Equinox Software, Inc.
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
19 # Utility script to prepare a file of MARCXML records extracted from an Evergreen
20 # database for fingerprinter by adding 903 fields.  Usage:
21 #  echo "select id || chr(9) || REGEXP_REPLACE(marc, E'\\n','','g') from biblio.record_entry where not deleted and id < $BIBIDSTART" > $BIN/incumbent_bibs.sql 
22 #  psql -A -t -U $DBUSER < $BIN/incumbent_bibs.sql | munge_marc_export_for_fingerprint.pl > $INTER/incumbent.mrc
23
24 while (<>) {
25     my ($id, $rest) = split /\t/, $_, 2;
26     $rest =~ s!<datafield .*?tag="903".*?</datafield>!!g;
27     $rest =~ s!</record>!<datafield tag="903"><subfield code="a">$id</subfield></datafield></record>!;
28     $rest =~ s!</marc:record>!<datafield tag="903"><subfield code="a">$id</subfield></datafield></marc:record>!;
29     print $rest;
30 }
31