installer: command-line scripts improve finding C4 modules
[koha.git] / misc / dumpmarc.pl
1 #!/usr/bin/perl
2 # small script that dumps an iso2709 file.
3
4
5 use strict;
6 BEGIN {
7     # find Koha's Perl modules
8     # test carefully before changing this
9     use FindBin;
10     eval { require "$FindBin::Bin/kohalib.pl" };
11 }
12
13 # Koha modules used
14 use MARC::File::USMARC;
15 use MARC::Record;
16 use MARC::Batch;
17
18 use Getopt::Long;
19 my ( $input_marc_file,$number,$nowarning) = ('',0);
20 my $version;
21 GetOptions(
22     'file:s'    => \$input_marc_file,
23     'n:s' => \$number,
24     'v' => \$version,
25     'w' => \$nowarning,
26 );
27
28 warn "NUM : $number\n";
29 if ($version || ($input_marc_file eq '')) {
30         print <<EOF
31 small script to dump an iso2709 file.
32 parameters :
33 \tv : this version/help screen
34 \tfile /path/to/file/to/dump : the file to dump
35 \tn : the number of the record to dump. If missing, all the file is dumped
36 \tw : warning and strict off. If your dump fail, try -w option. It it works, then, the file is iso2709, but a buggy one !
37 SAMPLE : ./dumpmarc.pl -file /home/paul/koha.dev/local/npl -n 1
38 EOF
39 ;
40 die;
41 }
42
43 my $batch = MARC::Batch->new( 'USMARC', $input_marc_file );
44 $batch->warnings_off() unless $nowarning;
45 $batch->strict_off() unless $nowarning;
46 my $i=1;
47 while ( my $record = $batch->next() ) {
48         print "\nNUMBER $i =>\n".$record->as_formatted() if ($i eq $number || $number eq 0);
49         $i++;
50 }
51 print "\n==================\n$i record parsed\n";