a754bff06d507beaaf4498f4e0c013a6e9025499
[migration-tools.git] / ils-specific / unicorn / transform_unicorn_flat_bills.pl
1 #!/usr/bin/perl -w
2
3 my $count = 0;
4 my %records = ();
5
6 sub print_line {
7     print join("\t",
8         $records{ $count }{'FORM'} || '',
9         $records{ $count }{'USER_ID'} || '',
10         $records{ $count }{'ITEM_ID'} || '',
11         $records{ $count }{'BILL_LIBRARY'} || '',
12         $records{ $count }{'BILL_DB'} || '',
13         $records{ $count }{'BILL_AMOUNT'} || '',
14         $records{ $count }{'BILL_REASON'} || '',
15     ) . "\n"; 
16 }
17
18 print "FORM\tUSER_ID\tITEM_ID\tBILL_LIBRARY\tBILL_DB\tBILL_AMOUNT\tBILL_REASON\n";
19
20 while (my $line = <>) {
21     chomp $line; $line =~ s/[\r\n]//g;
22     if ($line =~ /DOCUMENT BOUNDARY/) {
23         if (defined $records{ $count }) {
24             print_line();
25         }
26         $count++; $records{ $count } = {};
27     }
28     if ($line =~ /FORM=(.+)/) {
29         $records{ $count }{'FORM'} = $1;
30     }
31     if ($line =~ /\.USER_ID\..+\|a(.+)/) {
32         $records{ $count }{'USER_ID'} = $1;
33     }
34     if ($line =~ /\.ITEM_ID\..+\|a(.+)/) {
35         $records{ $count }{'ITEM_ID'} = $1;
36     }
37     if ($line =~ /\.BILL_LIBRARY\..+\|a(.+)/) {
38         $records{ $count }{'BILL_LIBRARY'} = $1;
39     }
40     if ($line =~ /\.BILL_DB\..+\|a(.+)/) {
41         $records{ $count }{'BILL_DB'} = $1;
42     }
43     if ($line =~ /\.BILL_AMOUNT\..+\|a(.+)/) {
44         $records{ $count }{'BILL_AMOUNT'} = $1;
45     }
46     if ($line =~ /\.BILL_REASON\..+\|a(.+)/) {
47         $records{ $count }{'BILL_REASON'} = $1;
48     }
49 }
50 print_line();
51