#!/usr/local/bin/perl # implogidextract.pl # desc: extract bib IDs from log.imp* files # wordsettings: # end_autoz if ($#ARGV < 1) {usage();} $adesc = ''; $rdesc = ''; if ($ARGV[2] eq 'desc') {$adesc = 'A '; $rdesc = 'R ';} ### set up output file my $fout = sprintf(">%s", $ARGV[1]); my $fopen = sprintf("Cannot open %s for output\n", $fout); open(fout, $fout) or die $fopen; # read log file into array my $logfile = $ARGV[0]; $fopen = sprintf("Cannot open file %s for input\n", $logfile); open(logfile, $logfile) or die $fopen; @loglines = ; close(logfile); # process array foreach $l (@loglines) { if ($l =~ /Adding Bib record/) # record was added { $l =~ s/\s\s*/ /g; @word = split / /, $l; $word[4] =~ s/\.//g; print fout "$adesc$word[4]\n"; } elsif ($l =~ /REPLACE/) # record was replaced { $prevrec =~ s/\s\s*/ /g; @word = split / /, $prevrec; print fout "$rdesc$word[1]\n"; } $prevrec = $l; } close(fout); sub usage() { print ("\nUsage: implogidextract infile outfile \"desc\"\n\n"); print (" Given an input file of the Voyager log.imp format,\n"); print (" write the processed Bib IDs to outfile.\n\n"); print (" If the third parameter is present, it must be\n"); print (" the four letters desc. In that case,\n"); print (" Bib IDs are preceded by an A for add, and\n"); print (" an R for replace, to indicate the performed action.\n"); exit(0); }