user_library field
[migration-tools.git] / transform_unicorn_flat_charges.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 }{'CHRG_LIBRARY'} || '',
12         $records{ $count }{'CHRG_DC'} || '',
13         $records{ $count }{'CHRG_DATEDUE'} || '',
14     ) . "\n"; 
15 }
16
17 print "FORM\tUSER_ID\tITEM_ID\tCHRG_LIBRARY\tCHRG_DC\tCHRG_DATEDUE\n";
18
19 while (my $line = <>) {
20     chomp $line; $line =~ s/[\r\n]//g;
21     if ($line =~ /DOCUMENT BOUNDARY/) {
22         if (defined $records{ $count }) {
23             print_line();
24         }
25         $count++; $records{ $count } = {};
26     }
27     if ($line =~ /FORM=(.+)/) {
28         $records{ $count }{'FORM'} = $1;
29     }
30     if ($line =~ /\.USER_ID\..+\|a(.+)/) {
31         $records{ $count }{'USER_ID'} = $1;
32     }
33     if ($line =~ /\.ITEM_ID\..+\|a(.+)/) {
34         $records{ $count }{'ITEM_ID'} = $1;
35     }
36     if ($line =~ /\.CHRG_LIBRARY\..+\|a(.+)/) {
37         $records{ $count }{'CHRG_LIBRARY'} = $1;
38     }
39     if ($line =~ /\.CHRG_DC\..+\|a(.+)/) {
40         $records{ $count }{'CHRG_DC'} = $1;
41     }
42     if ($line =~ /\.CHRG_DATEDUE\..+\|a(.+)/) {
43         $records{ $count }{'CHRG_DATEDUE'} = $1;
44     }
45 }
46 print_line();
47