From: Shawn Boyette Date: Tue, 17 Mar 2009 16:57:11 +0000 (+0000) Subject: moving stuff, again, finishing X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=commitdiff_plain;h=c3c9f9574214df27a14aa911adf1349e47feee20 moving stuff, again, finishing --- diff --git a/database/clear-db.sql b/database/clear-db.sql deleted file mode 100644 index 1602265..0000000 --- a/database/clear-db.sql +++ /dev/null @@ -1,140 +0,0 @@ -SET CLIENT_ENCODING TO 'UNICODE'; - -BEGIN; - -SELECT reporter.disable_materialized_simple_record_trigger(); - -CREATE TEMP TABLE dummy_bib AS SELECT * FROM biblio.record_entry WHERE id = -1; -CREATE TEMP TABLE dummy_cn AS SELECT * FROM asset.call_number WHERE id = -1; - -CREATE TEMP TABLE backup_loc AS SELECT * FROM asset.copy_location WHERE id = 1; -CREATE TEMP TABLE backup_usr AS SELECT * FROM actor.usr WHERE id = 1; -CREATE TEMP TABLE backup_card AS SELECT * FROM actor.card WHERE usr IN (SELECT id FROM backup_usr); - -UPDATE backup_usr SET card = NULL; - -DROP INDEX metabib.metabib_full_rec_index_vector_idx; -DROP INDEX metabib.metabib_full_value_idx; -DROP INDEX metabib.metabib_title_field_entry_index_vector_idx; -DROP INDEX metabib.metabib_author_field_entry_index_vector_idx; -DROP INDEX metabib.metabib_subject_field_entry_index_vector_idx; -DROP INDEX metabib.metabib_keyword_field_entry_index_vector_idx; -DROP INDEX metabib.metabib_series_field_entry_index_vector_idx; -DROP INDEX metabib.metabib_full_rec_tag_subfield_idx; - - -TRUNCATE biblio.record_entry CASCADE; -TRUNCATE metabib.full_rec; -TRUNCATE metabib.rec_descriptor; -TRUNCATE metabib.title_field_entry; -TRUNCATE metabib.author_field_entry; -TRUNCATE metabib.subject_field_entry; -TRUNCATE metabib.keyword_field_entry; -TRUNCATE metabib.series_field_entry; -TRUNCATE auditor.biblio_record_entry_history; -TRUNCATE asset.copy_location CASCADE; - -TRUNCATE actor.usr CASCADE; -TRUNCATE actor.card CASCADE; -TRUNCATE actor.usr_address CASCADE; -TRUNCATE actor.stat_cat CASCADE; -TRUNCATE actor.stat_cat_entry_usr_map CASCADE; -TRUNCATE money.grocery CASCADE; -TRUNCATE money.billing CASCADE; -TRUNCATE action.circulation CASCADE; -TRUNCATE action.hold_request CASCADE; - -SELECT SETVAL('biblio.record_entry_id_seq', 1); - -SELECT SETVAL('money.billable_xact_id_seq', 1); -SELECT SETVAL('money.billing_id_seq', 1); - -SELECT SETVAL('action.hold_request_id_seq', 1); - -SELECT SETVAL('asset.call_number_id_seq', 2); -SELECT SETVAL('asset.copy_id_seq', 1); -SELECT SETVAL('asset.copy_location_id_seq', 2); -SELECT SETVAL('asset.stat_cat_id_seq', 1); -SELECT SETVAL('asset.stat_cat_entry_id_seq', 1); -SELECT SETVAL('asset.stat_cat_entry_copy_map_id_seq', 1); - -SELECT SETVAL('actor.usr_id_seq', 2); -SELECT SETVAL('actor.card_id_seq', 2); -SELECT SETVAL('actor.usr_address_id_seq', 2); -SELECT SETVAL('actor.stat_cat_id_seq', 1); -SELECT SETVAL('actor.stat_cat_entry_id_seq', 1); -SELECT SETVAL('actor.stat_cat_entry_usr_map_id_seq', 1); - -SELECT SETVAL('metabib.full_rec_id_seq', 1); -SELECT SETVAL('metabib.rec_descriptor_id_seq', 1); -SELECT SETVAL('metabib.title_field_entry_id_seq', 1); -SELECT SETVAL('metabib.author_field_entry_id_seq', 1); -SELECT SETVAL('metabib.subject_field_entry_id_seq', 1); -SELECT SETVAL('metabib.keyword_field_entry_id_seq', 1); -SELECT SETVAL('metabib.series_field_entry_id_seq', 1); -SELECT SETVAL('metabib.metarecord_id_seq', 1); -SELECT SETVAL('metabib.metarecord_source_map_id_seq', 1); - -INSERT INTO biblio.record_entry SELECT * FROM dummy_bib; -INSERT INTO asset.call_number SELECT * FROM dummy_cn; -INSERT INTO asset.copy_location SELECT * FROM backup_loc; -INSERT INTO actor.usr SELECT * FROM backup_usr; -INSERT INTO actor.card SELECT * FROM backup_card; -UPDATE actor.usr SET card = actor.card.id FROM actor.card WHERE actor.usr.id = actor.card.usr; -SELECT SETVAL('actor.usr_id_seq', (SELECT MAX(id)+1 FROM actor.usr)); -SELECT SETVAL('actor.card_id_seq', (SELECT MAX(id)+1 FROM actor.card)); - --- Put any scripts that reload bibs/items/etc here. Example included. -/* - -\i incumbent.sql -\i incoming.sql - -*/ -\i IN.sql - -CREATE INDEX metabib_title_field_entry_index_vector_idx ON metabib.title_field_entry USING GIST (index_vector); -CREATE INDEX metabib_author_field_entry_index_vector_idx ON metabib.author_field_entry USING GIST (index_vector); -CREATE INDEX metabib_subject_field_entry_index_vector_idx ON metabib.subject_field_entry USING GIST (index_vector); -CREATE INDEX metabib_keyword_field_entry_index_vector_idx ON metabib.keyword_field_entry USING GIST (index_vector); -CREATE INDEX metabib_series_field_entry_index_vector_idx ON metabib.series_field_entry USING GIST (index_vector); -CREATE INDEX metabib_full_rec_index_vector_idx ON metabib.full_rec USING GIST (index_vector); -CREATE INDEX metabib_full_rec_tag_subfield_idx ON metabib.full_rec (tag,subfield); -CREATE INDEX metabib_full_value_idx ON metabib.full_rec (value); - -/* Run the AFTER committing ... - -ALTER TABLE metabib.metarecord_source_map DROP CONSTRAINT metabib_metarecord_source_map_metarecord_fkey; - -TRUNCATE metabib.metarecord; -TRUNCATE metabib.metarecord_source_map; - -INSERT INTO metabib.metarecord (fingerprint,master_record) - SELECT fingerprint,id - FROM (SELECT DISTINCT ON (fingerprint) - fingerprint, id, quality - FROM biblio.record_entry - ORDER BY fingerprint, quality desc) AS x - WHERE fingerprint IS NOT NULL; - -INSERT INTO metabib.metarecord_source_map (metarecord,source) - SELECT m.id, b.id - FROM biblio.record_entry b - JOIN metabib.metarecord m ON (m.fingerprint = b.fingerprint); - -ALTER TABLE metabib.metarecord_source_map - ADD CONSTRAINT metabib_metarecord_source_map_metarecord_fkey - FOREIGN KEY (metarecord) REFERENCES metabib.metarecord (id) DEFERRABLE INITIALLY DEFERRED; - -*/ - - -/* And this too, if it's production - -SELECT reporter.enable_materialized_simple_record_trigger(); - -*/ - --- COMMIT; --- VACUUM FULL; - diff --git a/database/final.load-bib.sql b/database/final.load-bib.sql deleted file mode 100644 index b2108e4..0000000 --- a/database/final.load-bib.sql +++ /dev/null @@ -1,80 +0,0 @@ -SET CLIENT_ENCODING TO 'UNICODE'; - -BEGIN; - -SELECT reporter.disable_materialized_simple_record_trigger(); - -CREATE TEMP TABLE dummy_bib AS SELECT * FROM biblio.record_entry WHERE id = -1; -CREATE TEMP TABLE dummy_cn AS SELECT * FROM asset.call_number WHERE id = -1; - -DROP INDEX metabib.metabib_full_rec_index_vector_idx; -DROP INDEX metabib.metabib_title_field_entry_index_vector_idx; -DROP INDEX metabib.metabib_author_field_entry_index_vector_idx; -DROP INDEX metabib.metabib_subject_field_entry_index_vector_idx; -DROP INDEX metabib.metabib_keyword_field_entry_index_vector_idx; -DROP INDEX metabib.metabib_series_field_entry_index_vector_idx; - -TRUNCATE biblio.record_entry CASCADE; -TRUNCATE metabib.full_rec; -TRUNCATE metabib.rec_descriptor; -TRUNCATE metabib.title_field_entry; -TRUNCATE metabib.author_field_entry; -TRUNCATE metabib.subject_field_entry; -TRUNCATE metabib.keyword_field_entry; -TRUNCATE metabib.series_field_entry; -TRUNCATE auditor.biblio_record_entry_history; - -SELECT SETVAL('biblio.record_entry_id_seq', 1); -SELECT SETVAL('metabib.full_rec_id_seq', 1); -SELECT SETVAL('metabib.rec_descriptor_id_seq', 1); -SELECT SETVAL('metabib.title_field_entry_id_seq', 1); -SELECT SETVAL('metabib.author_field_entry_id_seq', 1); -SELECT SETVAL('metabib.subject_field_entry_id_seq', 1); -SELECT SETVAL('metabib.keyword_field_entry_id_seq', 1); -SELECT SETVAL('metabib.series_field_entry_id_seq', 1); -SELECT SETVAL('metabib.metarecord_id_seq', 1); -SELECT SETVAL('metabib.metarecord_source_map_id_seq', 1); - -INSERT INTO biblio.record_entry SELECT * FROM dummy_bib; -INSERT INTO asset.call_number SELECT * FROM dummy_cn; - -\i incumbent.sql -\i incoming.sql - -CREATE INDEX metabib_title_field_entry_index_vector_idx ON metabib.title_field_entry USING GIST (index_vector); -CREATE INDEX metabib_author_field_entry_index_vector_idx ON metabib.author_field_entry USING GIST (index_vector); -CREATE INDEX metabib_subject_field_entry_index_vector_idx ON metabib.subject_field_entry USING GIST (index_vector); -CREATE INDEX metabib_keyword_field_entry_index_vector_idx ON metabib.keyword_field_entry USING GIST (index_vector); -CREATE INDEX metabib_series_field_entry_index_vector_idx ON metabib.series_field_entry USING GIST (index_vector); -CREATE INDEX metabib_full_rec_index_vector_idx ON metabib.full_rec USING GIST (index_vector); -CREATE INDEX metabib_full_rec_tag_subfield_idx ON metabib.full_rec (tag,subfield); -CREATE INDEX metabib_full_value_idx ON metabib.full_rec (value); - -ALTER TABLE metabib.metarecord_source_map DROP CONSTRAINT metabib_metarecord_source_map_metarecord_fkey; - -TRUNCATE metabib.metarecord; -TRUNCATE metabib.metarecord_source_map; - -INSERT INTO metabib.metarecord (fingerprint,master_record) - SELECT fingerprint,id - FROM (SELECT DISTINCT ON (fingerprint) - fingerprint, id, quality - FROM biblio.record_entry - ORDER BY fingerprint, quality desc) AS x - WHERE fingerprint IS NOT NULL; - -INSERT INTO metabib.metarecord_source_map (metarecord,source) - SELECT m.id, b.id - FROM biblio.record_entry b - JOIN metabib.metarecord m ON (m.fingerprint = b.fingerprint); - -ALTER TABLE metabib.metarecord_source_map - ADD CONSTRAINT metabib_metarecord_source_map_metarecord_fkey - FOREIGN KEY (metarecord) REFERENCES metabib.metarecord (id) DEFERRABLE INITIALLY DEFERRED; - -SELECT reporter.enable_materialized_simple_record_trigger(); - - --- COMMIT; --- VACUUM FULL; - diff --git a/database/query_for_primary_matching_incumbent_record.pl b/database/query_for_primary_matching_incumbent_record.pl deleted file mode 100755 index ee504dd..0000000 --- a/database/query_for_primary_matching_incumbent_record.pl +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/perl -use DBI; -use Data::Dumper; - -################ THIS RESOURCE IS FOR PINES PRODUCTION -my $SOURCE_DBI_RESOURCE = "dbi:Pg:dbname=sparkle;host=10.1.0.12;port=5432"; -my $SOURCE_DBI_USER = 'postgres'; -my $SOURCE_DBI_PASSWD = ''; -my $source_dbh = DBI->connect($SOURCE_DBI_RESOURCE, $SOURCE_DBI_USER, $SOURCE_DBI_PASSWD) or die("Database error: $DBI::errstr"); -my $primary_fingerprint_tablename = "public.quitman_full_fingerprint_set"; - -sub fetch_record { - - my $item_form = shift; - my $date1 = shift; - my $record_type = shift; - my $bib_lvl = shift; - my $title = shift; - my $sql = "select id from $primary_fingerprint_tablename where " . join(' AND ', - " item_form = ".$source_dbh->quote($item_form), - " substring = ".$source_dbh->quote($date1), - " item_type = ".$source_dbh->quote($record_type), - " bib_level = ".$source_dbh->quote($bib_lvl), - " title = ".$source_dbh->quote($title), - ); - my $source_sth = $source_dbh->prepare($sql) or die("prepare error: $DBI::errstr \n[$sql]"); - $source_sth->execute() or die("execute error: $DBI::errstr \n[$sql]"); - - while ( my ($id) = $source_sth->fetchrow_array ) { - - print "$id\n"; - - } - $source_sth->finish(); - - -} - -while (my $line = <>) { - chomp $line; - my ($id,$item_form,$date1,$record_type,$bib_lvl,$title) = split(/\t/,$line); - if ($id eq 'id') { next; } - fetch_record($item_form,$date1,$record_type,$bib_lvl,$title); -} - -$source_dbh->disconnect; - diff --git a/ils-specific/parse-tlc-items-out.pl b/ils-specific/parse-tlc-items-out.pl deleted file mode 100644 index 2cee130..0000000 --- a/ils-specific/parse-tlc-items-out.pl +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/perl - -# This parses TCL items-out reports converted from excel to csv, turning them -# into a tab separated file. arg! - -my $state; -my $patron; -my $item; -my $out; -my $due; -my $price; - -my ($a,$b,$c,$d,$e,$f,$g) = (0,1,2,3,4,5,6,7); - -print "patron\titem\tout\tdue\tprice\n"; - -while (<>) { - chomp; - my @fields = split /\t/; - - if ( (!$state || $state eq 'item' || $state eq 'none') && $fields[$f] eq 'Borrower ID') { - $state = 'borrower'; - next; - } - - if ($state eq 'borrower') { - $patron = $fields[$f]; - $state = 'none'; - next; - } - - if ($state eq 'none' && $fields[$b] eq 'Item ID') { - $state = 'item'; - next; - } - - if ($state eq 'item' && $fields[$b] =~ /^\d+$/o) { - $item = $fields[$b]; - if ($fields[$f] =~ /^(\d+)\/(\d+)\/(\d+)$/) { - $out = sprintf('%04d-%02d-%02d', 2000 + $3, $1, $2); - } - if ($fields[$e] =~ /^(\d+)\/(\d+)\/(\d+)$/) { - $due = sprintf('%04d-%02d-%02d', 2000 + $3, $1, $2); - } - ($price = $fields[$g]) =~ s/\*//go; - print join("\t", $patron, $item, $out, $due, $price) . "\n"; - } -} diff --git a/ils-specific/spit_spectrum_marc_holdings.pl b/ils-specific/spit_spectrum_marc_holdings.pl deleted file mode 100755 index 0873d17..0000000 --- a/ils-specific/spit_spectrum_marc_holdings.pl +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/perl -use open ':utf8'; -use MARC::Batch; -use MARC::File::XML ( BinaryEncoding => 'utf-8' ); -use MARC::Field; -use Unicode::Normalize; - -my $filetype = $ARGV[0]; # XML or USMARC -my $filename = $ARGV[1]; -if (! $filetype && ! $filename ) { die "./script \n"; } - -my $count = 0; - -binmode(STDOUT, ':utf8'); -binmode(STDIN, ':utf8'); - -print join("\t", - "bib_id", - "bib001", - "material_number", - "call_number", - "copy_location", - "price_and_vendor", - "subf_b", - "subf_x", - "bib961u" -) . "\n"; - - -print STDERR "Processing " . $ARGV[$argnum] . "\n"; - -my $M; -open $M, '<:utf8', $ARGV[1]; -my $batch = MARC::Batch->new($ARGV[0],$M); - -$batch->strict_off(); -$batch->warnings_off(); - -while ( my $record = $batch->next() ) { - - $count++; - - print STDERR "WARNINGS: Record $count : " . join(":",@warnings) . " : continuing...\n" if ( @warnings ); - my $my_903 = $record->field('903'); - my $my_903a = $my_903 ? $my_903->subfield('a') : ''; # target bib id's here - my @my_961_tags = $record->field('961'); my $bib961u = ''; - foreach my $my_961 ( @my_961_tags ) { - my @subfield_u = $my_961->subfield('u'); - foreach my $u ( @subfield_u ) { - $bib961u .= $u . "|"; - } - } - $bib961u =~ s/\|$//; - my @tags = $record->field('852'); - foreach my $tag ( @tags ) { - if ($tag->subfield('p')) { # if material_number - print join("\t", - $my_903a, # bib id - $record->field('001') ? $record->field('001')->as_string() : '', #bib001 - $tag->subfield('p') || '', # material_number - $tag->subfield('h') || '', # call_number - $tag->subfield('c') || '', # copy_location - $tag->subfield('9') || '', # price_and_vendor - $tag->subfield('b') || '', # subf_b - $tag->subfield('x') || '', # subf_x - $bib961u # bib961u - ) . "\n"; - } - } - -} -print STDERR "Processed $count records\n"; diff --git a/ils-specific/spit_tlc_marc_holdings.pl b/ils-specific/spit_tlc_marc_holdings.pl deleted file mode 100755 index 7580393..0000000 --- a/ils-specific/spit_tlc_marc_holdings.pl +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/perl -use open ':utf8'; -use MARC::Batch; -use MARC::File::XML ( BinaryEncoding => 'utf-8' ); -use MARC::Field; -use Unicode::Normalize; - -my $count = 0; - -binmode(STDOUT, ':utf8'); -binmode(STDIN, ':utf8'); - -print join("\t", - "bib id", - "collection code", - "prefix", - "call number", - "cutter number", - "barcode", - "serial year", - "volume number", - "part subdivision 1", - "part subdivision 2", - "part subdivision 3", - "part subdivision 4", - "copy number", - "accession number", - "price", - "condition", - "magnetic media", - "checkin-in/check-out note" -) . "\n"; - -foreach my $argnum ( 0 .. $#ARGV ) { - - print STDERR "Processing " . $ARGV[$argnum] . "\n"; - - my $M; - open $M, '<:utf8', $ARGV[$argnum]; - my $batch = MARC::Batch->new('XML',$M); - - $batch->strict_off(); - $batch->warnings_off(); - - while ( my $record = $batch->next() ) { - - $count++; - - print STDERR "WARNINGS: Record $count : " . join(":",@warnings) . " : continuing...\n" if ( @warnings ); - my $my_903a = $record->field('903')->subfield('a'); # target bib id's here - my @tags = $record->field('949'); - foreach my $tag ( @tags ) { - if ($tag->subfield('g')) { - print join("\t", - $my_903a, # bib id - $tag->subfield('a') || '', # collection code - $tag->subfield('b') || '', # prefix - $tag->subfield('c') || '', # call number - $tag->subfield('d') || '', # cutter number - $tag->subfield('g') || '', # barcode - $tag->subfield('h') || '', # serial year - $tag->subfield('i') || '', # volume number - $tag->subfield('j') || '', # part subdivision 1 - $tag->subfield('k') || '', # part subdivision 2 - $tag->subfield('l') || '', # part subdivision 3 - $tag->subfield('m') || '', # part subdivision 4 - $tag->subfield('n') || '', # copy number - $tag->subfield('o') || '', # accession number - $tag->subfield('p') || '', # price - $tag->subfield('q') || '', # condition - $tag->subfield('5') || '', # magnetic media - $tag->subfield('7') || '' # checkin-in/check-out note - ) . "\n"; - } - } - - } - print STDERR "Processed $count records\n"; -} diff --git a/ils-specific/unicorn/split_unicorn_marc_holdings.pl b/ils-specific/unicorn/split_unicorn_marc_holdings.pl deleted file mode 100755 index c99d1a1..0000000 --- a/ils-specific/unicorn/split_unicorn_marc_holdings.pl +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/perl -use open ':utf8'; -use MARC::Batch; -use MARC::File::XML ( BinaryEncoding => 'utf-8' ); -use MARC::Field; -use Unicode::Normalize; - -my $count = 0; - -binmode(STDOUT, ':utf8'); -binmode(STDIN, ':utf8'); - -print join("\t", - "bib id", - "library", - "barcode", - "current location", - "home location", - "call number", - "item type", - "acq date", - "price", - "circulate flag", - "total charges", - "cat1", - "cat2" -) . "\n"; - -foreach my $argnum ( 0 .. $#ARGV ) { - - print STDERR "Processing " . $ARGV[$argnum] . "\n"; - - my $M; - open $M, '<:utf8', $ARGV[$argnum]; - my $batch = MARC::Batch->new('XML',$M); - - $batch->strict_off(); - $batch->warnings_off(); - - while ( my $record = $batch->next() ) { - - $count++; - - print STDERR "WARNINGS: Record $count : " . join(":",@warnings) . " : continuing...\n" if ( @warnings ); - my $my_903a = $record->field('903')->subfield('a'); # target bib id's here - my @tags = $record->field('999'); - foreach my $tag ( @tags ) { - print join("\t", - $my_903a, - $tag->subfield('m') || '', # library - $tag->subfield('i') || '', # barcode - $tag->subfield('k') || '', # current location - $tag->subfield('l') || '', # home location - $tag->subfield('a') || '', # call number - $tag->subfield('t') || '', # item type - $tag->subfield('u') || '', # acq date - $tag->subfield('p') || '', # price - $tag->subfield('r') || '', # circulate flag - $tag->subfield('n') || '', # total charges - $tag->subfield('x') || '', # cat1 - $tag->subfield('z') || '' # cat2 - ) . "\n"; - } - - } - print STDERR "Processed $count records\n"; -} diff --git a/ils-specific/unicorn/transform_unicorn_flat_bills.pl b/ils-specific/unicorn/transform_unicorn_flat_bills.pl deleted file mode 100755 index a754bff..0000000 --- a/ils-specific/unicorn/transform_unicorn_flat_bills.pl +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/perl -w - -my $count = 0; -my %records = (); - -sub print_line { - print join("\t", - $records{ $count }{'FORM'} || '', - $records{ $count }{'USER_ID'} || '', - $records{ $count }{'ITEM_ID'} || '', - $records{ $count }{'BILL_LIBRARY'} || '', - $records{ $count }{'BILL_DB'} || '', - $records{ $count }{'BILL_AMOUNT'} || '', - $records{ $count }{'BILL_REASON'} || '', - ) . "\n"; -} - -print "FORM\tUSER_ID\tITEM_ID\tBILL_LIBRARY\tBILL_DB\tBILL_AMOUNT\tBILL_REASON\n"; - -while (my $line = <>) { - chomp $line; $line =~ s/[\r\n]//g; - if ($line =~ /DOCUMENT BOUNDARY/) { - if (defined $records{ $count }) { - print_line(); - } - $count++; $records{ $count } = {}; - } - if ($line =~ /FORM=(.+)/) { - $records{ $count }{'FORM'} = $1; - } - if ($line =~ /\.USER_ID\..+\|a(.+)/) { - $records{ $count }{'USER_ID'} = $1; - } - if ($line =~ /\.ITEM_ID\..+\|a(.+)/) { - $records{ $count }{'ITEM_ID'} = $1; - } - if ($line =~ /\.BILL_LIBRARY\..+\|a(.+)/) { - $records{ $count }{'BILL_LIBRARY'} = $1; - } - if ($line =~ /\.BILL_DB\..+\|a(.+)/) { - $records{ $count }{'BILL_DB'} = $1; - } - if ($line =~ /\.BILL_AMOUNT\..+\|a(.+)/) { - $records{ $count }{'BILL_AMOUNT'} = $1; - } - if ($line =~ /\.BILL_REASON\..+\|a(.+)/) { - $records{ $count }{'BILL_REASON'} = $1; - } -} -print_line(); - diff --git a/ils-specific/unicorn/transform_unicorn_flat_charges.pl b/ils-specific/unicorn/transform_unicorn_flat_charges.pl deleted file mode 100755 index 9f53e87..0000000 --- a/ils-specific/unicorn/transform_unicorn_flat_charges.pl +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/perl -w - -my $count = 0; -my %records = (); - -sub print_line { - print join("\t", - $records{ $count }{'FORM'} || '', - $records{ $count }{'USER_ID'} || '', - $records{ $count }{'ITEM_ID'} || '', - $records{ $count }{'CHRG_LIBRARY'} || '', - $records{ $count }{'CHRG_DC'} || '', - $records{ $count }{'CHRG_DATEDUE'} || '', - $records{ $count }{'CHRG_DATE_CLMRET'} || '', - ) . "\n"; -} - -print "FORM\tUSER_ID\tITEM_ID\tCHRG_LIBRARY\tCHRG_DC\tCHRG_DATEDUE\tCHRG_DATE_CLMRET\n"; - -while (my $line = <>) { - chomp $line; $line =~ s/[\r\n]//g; - if ($line =~ /DOCUMENT BOUNDARY/) { - if (defined $records{ $count }) { - print_line(); - } - $count++; $records{ $count } = {}; - } - if ($line =~ /FORM=(.+)/) { - $records{ $count }{'FORM'} = $1; - } - if ($line =~ /\.USER_ID\..+\|a(.+)/) { - $records{ $count }{'USER_ID'} = $1; - } - if ($line =~ /\.ITEM_ID\..+\|a(.+)/) { - $records{ $count }{'ITEM_ID'} = $1; - } - if ($line =~ /\.CHRG_LIBRARY\..+\|a(.+)/) { - $records{ $count }{'CHRG_LIBRARY'} = $1; - } - if ($line =~ /\.CHRG_DC\..+\|a(.+)/) { - $records{ $count }{'CHRG_DC'} = $1; - } - if ($line =~ /\.CHRG_DATEDUE\..+\|a(.+)/) { - $records{ $count }{'CHRG_DATEDUE'} = $1; - } - if ($line =~ /\.CHRG_DATE_CLMRET\..+\|a(.+)/) { - $records{ $count }{'CHRG_DATE_CLMRET'} = $1; - } -} -print_line(); - diff --git a/ils-specific/unicorn/unicorn_patron_xml2text.pl b/ils-specific/unicorn/unicorn_patron_xml2text.pl deleted file mode 100755 index 296bf54..0000000 --- a/ils-specific/unicorn/unicorn_patron_xml2text.pl +++ /dev/null @@ -1,218 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -use DateTime; -use Time::HiRes qw/time/; -use XML::LibXML; - -my %s_map; - -my $doc = XML::LibXML->new->parse_file($ARGV[0]); - -my $starttime = time; -my $count = 1; - -my @base_elements = ( - "user_id", - "user_altid", -# "user_pin", - "user_profile", - "user_status", - "user_library", - "user_priv_granted", - "user_priv_expires", - "user_mailingaddr", - "birthdate", - "last_name", - "first_name", - "middle_name", - "suffix_name", - "note", -# "note1", - "patron", - "comment", -# "staff", -# "webcatpref", - "user_category1", -# "user_category2", - "user_category3", -# "user_category4", -# "dept", -# "guardian", -# "license", - # "aup", -# "photo", -# "notify_via", -# "user_claims_ret", -# "user_environment", -# "user_department", - "ums_id", - "user_last_activity", - "placcard", - "user_email", -); - -my @addr_elements = ( - "std_line1", - "std_line2", - "std_city", - "std_state", - "std_zip", -# "phone", -# "dayphone", - "homephone", -# "workphone", -# "cellphone", -# "email", -# "location", -# "usefor", -# "care_of", -# "known_bad", - "ums_addrid", -); - -print STDOUT join("\t", @base_elements); -foreach my $addr ( 1..3 ) { - print STDOUT "\t" . join("\t", @addr_elements); -} -print STDOUT "\tuserid_active\tinactive_barcode1\tinactive_barcode2"; -print STDOUT "\n"; - -for my $patron ( $doc->documentElement->childNodes ) { - next if ($patron->nodeType == 3); - - my $bc = $patron->findvalue( 'user_id' ); $bc =~ s/^\s+//; $bc =~ s/\s+$//; - if (exists($s_map{$bc})) { - $count++; - warn "\n!!! already saw barcode $bc, skipping\n"; - next; - } else { - $s_map{$bc} = 1; - } - - unless (defined($bc)) { - my $xml = $patron->toString; - warn "\n!!! no barcode found in UMS data, user number $count, xml => $xml \n"; - $count++; - next; - } - - foreach my $e ( @base_elements ) { - my $v = $patron->findvalue( $e ); $v =~ s/^\s+//; $v =~ s/\s+$//; - if ( $v && ( $e eq 'birthdate' || $e eq 'user_priv_granted' || $e eq 'user_priv_expires' ) ) { $v = parse_date($v); } - print STDOUT ( $v ? $v : '' ) . "\t"; - } - - my %addresses; - - for my $addr ( $patron->findnodes( "Address" ) ) { - my $addr_type = $addr->getAttribute('addr_type'); - $addresses{$addr_type} = $addr; - } - - foreach my $t ( 1..3 ) { - if ($addresses{$t}) { - foreach my $e ( @addr_elements ) { - my $v; - if ($e eq "known_bad") { - $v = $addresses{$t}->getAttribute( $e ); if ($v) { $v =~ s/^\s+//; $v =~ s/\s+$//; } - } else { - $v = $addresses{$t}->findvalue( $e ); $v =~ s/^\s+//; $v =~ s/\s+$//; - } - print STDOUT ( $v ? $v : '' ) . "\t"; - } - } else { - foreach ( @addr_elements ) { print STDOUT "\t"; } - } - } - - my $inactive_barcode1 = ''; - my $inactive_barcode2 = ''; - my $userid_active = 't'; - my @barcodes = $patron->findnodes( "barcodes" ); - for my $i_bc ( $barcodes[0]->findnodes( "barcode" ) ) { - my $active = $i_bc->getAttribute('active'); - if ($active eq "0" && $i_bc->textContent eq $bc) { - $userid_active = 'f'; - } - if ($active eq "0" && $i_bc->textContent ne $bc) { - if (! $inactive_barcode1 ) { - $inactive_barcode1 = $i_bc->textContent; - $inactive_barcode1 =~ s/^\s+//; - $inactive_barcode1 =~ s/\s+$//; - } else { - if (! $inactive_barcode2 ) { - $inactive_barcode2 = $i_bc->textContent; - $inactive_barcode2 =~ s/^\s+//; - $inactive_barcode2 =~ s/\s+$//; - } else { - warn "Extra barcode (" . $i_bc->textContent . ") for user with id = " . $bc . "\n"; - } - } - } - } - print STDOUT "$userid_active\t$inactive_barcode1\t$inactive_barcode2"; - - print STDOUT "\n"; - $count++; -} - -sub parse_date { - my $string = shift; - my $group = shift; - - my ($y,$m,$d); - - if ($string eq 'NEVER') { - my (undef,undef,undef,$d,$m,$y) = localtime(); - return sprintf('%04d-%02d-%02d', $y + 1920, $m + 1, $d); - } elsif (length($string) == 8 && $string =~ /^(\d{4})(\d{2})(\d{2})$/o) { - ($y,$m,$d) = ($1,$2,$3); - } elsif ($string =~ /(\d+)\D(\d+)\D(\d+)/o) { #looks like it's parsable - if ( length($3) > 2 ) { # looks like mm.dd.yyyy - if ( $1 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) { - if ($1 > 12 && $1 < 31 && $2 < 13) { # well, actually it looks like dd.mm.yyyy - ($y,$m,$d) = ($3,$2,$1); - } elsif ($2 > 12 && $2 < 31 && $1 < 13) { - ($y,$m,$d) = ($3,$1,$2); - } - } - } elsif ( length($1) > 3 ) { # format probably yyyy.mm.dd - if ( $3 < 99 && $2 < 99 && $1 > 0 && $2 > 0 && $3 > 0) { - if ($2 > 12 && $2 < 32 && $3 < 13) { # well, actually it looks like yyyy.dd.mm -- why, I don't konw - ($y,$m,$d) = ($1,$3,$2); - } elsif ($3 > 12 && $3 < 31 && $2 < 13) { - ($y,$m,$d) = ($1,$2,$3); - } - } - } elsif ( $1 < 99 && $2 < 99 && $3 < 99 && $1 > 0 && $2 > 0 && $3 > 0) { - if ($3 < 7) { # probably 2000 or greater, mm.dd.yy - $y = $3 + 2000; - if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy - ($m,$d) = ($2,$1); - } elsif ($2 > 12 && $2 < 32 && $1 < 13) { - ($m,$d) = ($1,$2); - } - } else { # probably before 2000, mm.dd.yy - $y = $3 + 1900; - if ($1 > 12 && $1 < 32 && $2 < 13) { # well, actually it looks like dd.mm.yyyy - ($m,$d) = ($2,$1); - } elsif ($2 > 12 && $2 < 32 && $1 < 13) { - ($m,$d) = ($1,$2); - } - } - } - } - - my $date = $string; - if ($y && $m && $d) { - eval { - $date = sprintf('%04d-%02d-%-2d',$y, $m, $d) - if (new DateTime ( year => $y, month => $m, day => $d )); - } - } - - return $date; -} - diff --git a/oneliners/dump_inverse_select_marc.pl b/oneliners/dump_inverse_select_marc.pl deleted file mode 100755 index 249cad5..0000000 --- a/oneliners/dump_inverse_select_marc.pl +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/perl -use open ':utf8'; -use MARC::Batch; -use MARC::Record; -use MARC::File::XML ( BinaryEncoding => 'utf-8' ); -use MARC::Field; - -my $format = $ARGV[0]; - -my $record_id_file = $ARGV[1]; -my %record_ids; - -open FILE, $record_id_file; -while (my $record_id = ) { - chomp($record_id); $record_ids{ $record_id } = 1; -} -close FILE; - -my $id_tag = $ARGV[2]; my $id_subfield = $ARGV[3]; - -binmode(STDOUT, ':utf8'); -binmode(STDIN, ':utf8'); - -my $M; - -foreach $argnum ( 4 .. $#ARGV ) { - - print STDERR "Processing " . $ARGV[$argnum] . "\n"; - - open $M, '<:utf8', $ARGV[$argnum]; - - my $batch = MARC::Batch->new('XML',$M); - $batch->strict_off(); - $batch->warnings_off(); - - my $count = 0; - - while ( my $record = $batch->next() ) { - - $count++; - - my $id = $record->field($id_tag); - if (!$id) { - print STDERR "ERROR: This record is missing a $id_tag field.\n" . $record->as_formatted() . "\n=====\n"; - next; - } - $id = $id->as_string($id_subfield); - - if (! defined $record_ids{ $id }) { - if ($format eq 'text') { - print STDOUT '=-' x 39 . "\n"; - print STDOUT $record->as_formatted() . "\n"; - } else { - print STDOUT $record->as_xml() . "\n"; - } - } - } - print STDERR "Processed $count records.\n"; -} diff --git a/oneliners/select_marc.pl b/oneliners/select_marc.pl deleted file mode 100755 index cbd7fd9..0000000 --- a/oneliners/select_marc.pl +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/perl -use open ':utf8'; -use MARC::Batch; -use MARC::Record; -use MARC::File::XML ( BinaryEncoding => 'utf-8' ); -use MARC::Field; - -my $record_id_file = $ARGV[0]; -my %record_ids; - -open FILE, $record_id_file; -while (my $record_id = ) { - chomp($record_id); $record_ids{ $record_id } = 1; -} -close FILE; - -my $id_tag = $ARGV[1]; my $id_subfield = $ARGV[2]; - -binmode(STDOUT, ':utf8'); -binmode(STDIN, ':utf8'); - -my $M; - -foreach $argnum ( 3 .. $#ARGV ) { - - print STDERR "Processing " . $ARGV[$argnum] . "\n"; - - open $M, '<:utf8', $ARGV[$argnum]; - - my $batch = MARC::Batch->new('XML',$M); - $batch->strict_off(); - $batch->warnings_off(); - - my $count = 0; - - while ( my $record = $batch->next() ) { - - $count++; - - my $id = $record->field($id_tag); - if (!$id) { - print STDERR "ERROR: This record is missing a $id_tag field.\n" . $record->as_formatted() . "\n=====\n"; - next; - } - $id = $id->as_string($id_subfield); - - if (defined $record_ids{ $id }) { - open FILE, ">$id"; - binmode(FILE, ':utf8'); - print FILE $record->as_xml(); - close FILE; - } - } - print STDERR "Processed $count records.\n"; -} diff --git a/oneliners/select_marc_as_text.pl b/oneliners/select_marc_as_text.pl deleted file mode 100755 index 6a28e88..0000000 --- a/oneliners/select_marc_as_text.pl +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/perl -use open ':utf8'; -use MARC::Batch; -use MARC::Record; -use MARC::File::XML ( BinaryEncoding => 'utf-8' ); -use MARC::Field; - -my $inverse = $ARGV[0] eq "inverse"; - -my $record_id_file = $ARGV[1]; -my %record_ids; - -open FILE, $record_id_file; -while (my $record_id = ) { - chomp($record_id); $record_ids{ $record_id } = 1; -} -close FILE; - -my $id_tag = $ARGV[2]; my $id_subfield = $ARGV[3]; - -binmode(STDOUT, ':utf8'); -binmode(STDIN, ':utf8'); - -my $M; - -foreach $argnum ( 4 .. $#ARGV ) { - - print STDERR "Processing " . $ARGV[$argnum] . "\n"; - - open $M, '<:utf8', $ARGV[$argnum]; - - my $batch = MARC::Batch->new('XML',$M); - $batch->strict_off(); - $batch->warnings_off(); - - my $count = 0; - - while ( my $record = $batch->next() ) { - - $count++; - - my $id = $record->field($id_tag); - if (!$id) { - print STDERR "ERROR: This record is missing a $id_tag field.\n" . $record->as_formatted() . "\n=====\n"; - next; - } - $id = $id->as_string($id_subfield); - - if ( - ( ! $inverse && defined $record_ids{ $id } ) || - ( $inverse && ! defined $record_ids{ $id } ) - ) { - open FILE, ">$id.txt"; - binmode(FILE, ':utf8'); - print FILE $record->as_formatted(); - close FILE; - } - } - print STDERR "Processed $count records.\n"; -} diff --git a/oneliners/spit_csv.pl b/oneliners/spit_csv.pl deleted file mode 100755 index 8a02003..0000000 --- a/oneliners/spit_csv.pl +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/perl -use MARC::Batch; -use MARC::File::XML ( BinaryEncoding => 'utf-8' ); -#use MARC::Field; -use Unicode::Normalize; - - -my @desired_tags_subfields = (); -foreach my $argnum ( 1 .. $#ARGV) { - print STDERR $ARGV[$argnum] . "\n"; - push @desired_tags_subfields, $ARGV[$argnum]; -} - -my $count = 0; - -binmode(STDOUT, ':utf8'); -binmode(STDIN, ':utf8'); - -foreach my $argnum ( 0 .. 0 ) { - - print STDERR "Processing " . $ARGV[$argnum] . "\n"; - - #my $M; - #open $M, '<:utf8', $ARGV[$argnum]; - #my $batch = MARC::Batch->new('XML',$M); - my $batch = MARC::Batch->new('XML',$ARGV[$argnum]); - - $batch->strict_off(); - $batch->warnings_off(); - - while ( my $record = $batch->next() ) { - - $count++; - - print STDERR "WARNINGS: Record $count : " . join(":",@warnings) . " : continuing...\n" if ( @warnings ); - - my $first = 1; - for (my $i = 0; $i < scalar(@desired_tags_subfields); $i+=2) { - my @tags = (); - if ($record->field($desired_tags_subfields[$i])) { - @tags = $record->field($desired_tags_subfields[$i]); - } - if (scalar(@tags)>1) { - die "Multiple $desired_tags_subfields[$i]\n"; - } elsif (scalar(@tags)==0) { - print STDERR "Record $count missing $desired_tags_subfields[$i]\n"; - goto END_OF_WHILE; - } - foreach my $f ( @tags ) { - if ($f->subfield($desired_tags_subfields[$i+1])) { - if ($first) { - $first = 0; - } else { - print STDOUT "\t"; - } - print STDOUT $f->subfield($desired_tags_subfields[$i+1]); - } - } - } - print STDOUT "\n"; - END_OF_WHILE: - } - print STDERR "Processed $count records\n"; -} diff --git a/oneliners/spit_marc_903a_001.pl b/oneliners/spit_marc_903a_001.pl deleted file mode 100755 index b70b2d2..0000000 --- a/oneliners/spit_marc_903a_001.pl +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/perl -use MARC::Batch; -use MARC::File::XML ( BinaryEncoding => 'utf-8' ); -use MARC::Field; -use Unicode::Normalize; - -my $count = 0; - -binmode(STDOUT, ':utf8'); -binmode(STDIN, ':utf8'); - -foreach my $argnum ( 0 .. $#ARGV ) { - - print STDERR "Processing " . $ARGV[$argnum] . "\n"; - - my $M; - open $M, '<:utf8', $ARGV[$argnum]; - my $batch = MARC::Batch->new('XML',$M); - - $batch->strict_off(); - $batch->warnings_off(); - - while ( my $record = $batch->next() ) { - - $count++; - - print STDERR "WARNINGS: Record $count : " . join(":",@warnings) . " : continuing...\n" if ( @warnings ); - - my @my001 = $record->field('001'); - if (scalar(@my001) == 0 || scalar(@my001) > 1) { die "Wrong number of 001 tags for record $count\n"; } - my @my903 = $record->field('903'); - if (scalar(@my903) == 0 || scalar(@my903) > 1) { die "Wrong number of 903 tags for record $count\n"; } - print $my903[0]->subfield('a') . "\t" . $my001[0]->as_string() . "\n" - } - print STDERR "Processed $count records\n"; -} diff --git a/oneliners/spit_sample.pl b/oneliners/spit_sample.pl deleted file mode 100755 index 69a72db..0000000 --- a/oneliners/spit_sample.pl +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/perl -my @lines = <>; - -foreach my $i ( 1..20 ) { - $length = scalar( @lines ); - $idx = int rand ($length); - print $lines[$idx]; - splice(@lines,$idx,1); -} diff --git a/oneliners/spit_tag_multiplication.pl b/oneliners/spit_tag_multiplication.pl deleted file mode 100755 index 7a8408a..0000000 --- a/oneliners/spit_tag_multiplication.pl +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/perl -use MARC::Batch; -use MARC::File::XML ( BinaryEncoding => 'utf-8' ); -#use MARC::Field; -use Unicode::Normalize; - -my $filetype = $ARGV[0]; # XML or USMARC -my $filename = $ARGV[1]; -my $tag1 = $ARGV[2]; # use NONE for no subfield, such as in 001 -my $subfield1 = $ARGV[3]; -my $tag2 = $ARGV[4]; -my $subfield2 = $ARGV[5]; - -die "required arguments: filename tag1 subfield1 tag2 subfield2\n" if (! ($filename && $tag1 && $subfield1 && $tag2 && $subfield2) ); - -my $count = 0; - -binmode(STDOUT, ':utf8'); -binmode(STDIN, ':utf8'); - -print STDERR "Processing $filename\n"; - -my $batch = MARC::Batch->new($filetype,$filename); $batch->strict_off(); $batch->warnings_off(); - -while ( my $record = $batch->next() ) { - - $count++; - - print STDERR "WARNINGS: Record $count : " . join(":",@warnings) . " : continuing...\n" if ( @warnings ); - - my @tags1 = (); if ($record->field($tag1)) { @tags1 = $record->field($tag1); } else { next; } - - foreach my $f1 ( @tags1 ) { - if ($subfield1 eq 'NONE' ) { - - #*********************************************************************************************************************** - - my @tags2 = (); if ($record->field($tag2)) { @tags2 = $record->field($tag2); } else { next; } - - foreach my $f2 ( @tags2 ) { - if ($f2->subfield($subfield2)) { - my @subfields2 = $f2->subfield($subfield2); - foreach my $s2 ( @subfields2 ) { - print $f1->as_string() . "\t$s2\n"; - } - } - } - - #*********************************************************************************************************************** - - } else { - if ($f1->subfield($subfield1)) { - my @subfields1 = $f1->subfield($subfield1); - foreach my $s1 ( @subfields1 ) { - #*********************************************************************************************************************** - - my @tags2 = (); if ($record->field($tag2)) { @tags2 = $record->field($tag2); } else { next; } - - foreach my $f2 ( @tags2 ) { - if ($f2->subfield($subfield2)) { - my @subfields2 = $f2->subfield($subfield2); - foreach my $s2 ( @subfields2 ) { - print "$s1\t$s2\n"; - } - } - } - - #*********************************************************************************************************************** - } - } - } - } -} -print STDERR "Processed $count records\n"; diff --git a/oneliners/split_marc.pl b/oneliners/split_marc.pl deleted file mode 100644 index e6088b1..0000000 --- a/oneliners/split_marc.pl +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/perl -use open ':utf8'; -use MARC::Batch; -use MARC::Record; -use MARC::File::XML ( BinaryEncoding => 'utf-8' ); -use MARC::Field; -use POSIX; -use Error qw/:try/; - -my $split_every = $ARGV[0]; -my $count = 0; - -binmode(STDOUT, ':utf8'); -binmode(STDIN, ':utf8'); -my $M; - -foreach $argnum ( 1 .. $#ARGV ) { - - open $M, '<:utf8', $ARGV[$argnum]; - - print STDERR "Processing " . $ARGV[$argnum] . "\n"; - - my $batch = MARC::Batch->new('XML', $M); - $batch->strict_off(); - $batch->warnings_off(); - - my $record; - while ( try { $record = $batch->next() } otherwise { $record = -1 } ) { - next if ($record == -1); - $count++; - - my $filename = $ARGV[$argnum] . ".split." . floor( $count / $split_every ) . ".xml"; - - open FILE, ">>$filename"; - binmode(FILE, ':utf8'); - print FILE $record->as_xml(); - close FILE; - - $record = undef; - - unless ($count % 1000) { - print STDERR "$count\r" - } - - } - print STDERR "Processed $count records.\n"; -} - diff --git a/oneliners/spot_check.pl b/oneliners/spot_check.pl deleted file mode 100644 index 6f8011b..0000000 --- a/oneliners/spot_check.pl +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/perl -use open ':utf8'; -use MARC::Batch; -use MARC::Record; -use MARC::File::XML ( BinaryEncoding => 'utf-8' ); -use MARC::Field; - -my $count = 0; - -binmode(STDOUT, ':utf8'); -binmode(STDIN, ':utf8'); - -my $M; - -foreach $argnum ( 0 .. $#ARGV ) { - - print STDERR "Processing " . $ARGV[$argnum] . "\n"; - - open $M, '<:utf8', $ARGV[$argnum]; - - my $batch = MARC::Batch->new('XML',$M); - $batch->strict_off(); - $batch->warnings_off(); - - my $last_successful_record; - - eval { - while ( my $record = $batch->next() ) { - - $count++; - - $last_successful_record = $record->as_xml(); - - print STDERR "WARNINGS: Record $count : " . join(":",@warnings) . " : continuing...\n" if ( @warnings ); - - unless ($count % 1000) { - print STDERR "$count\r" - } - - } - }; - print STDERR "Processed $count records. Last successful record = " . $last_successful_record . "\n"; - warn $@ if $@; -} diff --git a/oneliners/trim_marc_based_on_tag_subfield_value.pl b/oneliners/trim_marc_based_on_tag_subfield_value.pl deleted file mode 100755 index b7ba249..0000000 --- a/oneliners/trim_marc_based_on_tag_subfield_value.pl +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/perl -use open ':utf8'; -use MARC::Batch; -use MARC::File::XML ( BinaryEncoding => 'utf-8' ); -use MARC::Field; -use Unicode::Normalize; - - -my $tag_number = $ARGV[0]; -my $tag_subfield = $ARGV[1]; -my $tag_value = $ARGV[2]; - -my $count = 0; - -binmode(STDOUT, ':utf8'); -binmode(STDIN, ':utf8'); - -foreach $argnum ( 3 .. $#ARGV ) { - - print STDERR "Processing " . $ARGV[$argnum] . "\n"; - - my $M; - open $M, '<:utf8', $ARGV[$argnum]; - my $batch = MARC::Batch->new('XML',$M); - - $batch->strict_off(); - $batch->warnings_off(); - - while ( my $record = $batch->next() ) { - - $count++; - - print STDERR "WARNINGS: Record $count : " . join(":",@warnings) . " : continuing...\n" if ( @warnings ); - - my $keep_me = 0; - - my @tags = (); - my @tags; if ($record->field($tag_number)) { @tags = $record->field($tag_number); } - foreach my $f ( @tags ) { - if ($f->subfield($tag_subfield)) { - if ( $f->subfield($tag_subfield)=~ m/($tag_value)/i ) { $keep_me = 1; } - } - } - - if ($keep_me) { - print STDOUT $record->as_xml(); - } - - } - print STDERR "Processed $count records\n"; -}