tab, not linefeed
[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         $records{ $count }{'CHRG_DATE_CLMRET'} || '',
15     ) . "\n"; 
16 }
17
18 print "FORM\tUSER_ID\tITEM_ID\tCHRG_LIBRARY\tCHRG_DC\tCHRG_DATEDUE\tCHRG_DATE_CLMRET\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 =~ /\.CHRG_LIBRARY\..+\|a(.+)/) {
38         $records{ $count }{'CHRG_LIBRARY'} = $1;
39     }
40     if ($line =~ /\.CHRG_DC\..+\|a(.+)/) {
41         $records{ $count }{'CHRG_DC'} = $1;
42     }
43     if ($line =~ /\.CHRG_DATEDUE\..+\|a(.+)/) {
44         $records{ $count }{'CHRG_DATEDUE'} = $1;
45     }
46     if ($line =~ /\.CHRG_DATEDUE\..+\|a(.+)/) {
47         $records{ $count }{'CHRG_DATE_CLMRET'} = $1;
48     }
49 }
50 print_line();
51