From 896725a108864a4de6e6ea72b91ada9e1e7a933d Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Fri, 25 Jul 2008 19:20:05 +0000 Subject: [PATCH] more unicorn conversion tools --- transform_unicorn_flat_bills.pl | 51 +++++++++++++++++++++++++++++++++++++ transform_unicorn_flat_charges.pl | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 0 deletions(-) create mode 100755 transform_unicorn_flat_bills.pl create mode 100755 transform_unicorn_flat_charges.pl diff --git a/transform_unicorn_flat_bills.pl b/transform_unicorn_flat_bills.pl new file mode 100755 index 0000000..a754bff --- /dev/null +++ b/transform_unicorn_flat_bills.pl @@ -0,0 +1,51 @@ +#!/usr/bin/perl -w + +my $count = 0; +my %records = (); + +sub print_line { + print join("\t", + $records{ $count }{'FORM'} || '', + $records{ $count }{'USER_ID'} || '', + $records{ $count }{'ITEM_ID'} || '', + $records{ $count }{'BILL_LIBRARY'} || '', + $records{ $count }{'BILL_DB'} || '', + $records{ $count }{'BILL_AMOUNT'} || '', + $records{ $count }{'BILL_REASON'} || '', + ) . "\n"; +} + +print "FORM\tUSER_ID\tITEM_ID\tBILL_LIBRARY\tBILL_DB\tBILL_AMOUNT\tBILL_REASON\n"; + +while (my $line = <>) { + chomp $line; $line =~ s/[\r\n]//g; + if ($line =~ /DOCUMENT BOUNDARY/) { + if (defined $records{ $count }) { + print_line(); + } + $count++; $records{ $count } = {}; + } + if ($line =~ /FORM=(.+)/) { + $records{ $count }{'FORM'} = $1; + } + if ($line =~ /\.USER_ID\..+\|a(.+)/) { + $records{ $count }{'USER_ID'} = $1; + } + if ($line =~ /\.ITEM_ID\..+\|a(.+)/) { + $records{ $count }{'ITEM_ID'} = $1; + } + if ($line =~ /\.BILL_LIBRARY\..+\|a(.+)/) { + $records{ $count }{'BILL_LIBRARY'} = $1; + } + if ($line =~ /\.BILL_DB\..+\|a(.+)/) { + $records{ $count }{'BILL_DB'} = $1; + } + if ($line =~ /\.BILL_AMOUNT\..+\|a(.+)/) { + $records{ $count }{'BILL_AMOUNT'} = $1; + } + if ($line =~ /\.BILL_REASON\..+\|a(.+)/) { + $records{ $count }{'BILL_REASON'} = $1; + } +} +print_line(); + diff --git a/transform_unicorn_flat_charges.pl b/transform_unicorn_flat_charges.pl new file mode 100755 index 0000000..18b8d71 --- /dev/null +++ b/transform_unicorn_flat_charges.pl @@ -0,0 +1,47 @@ +#!/usr/bin/perl -w + +my $count = 0; +my %records = (); + +sub print_line { + print join("\t", + $records{ $count }{'FORM'} || '', + $records{ $count }{'USER_ID'} || '', + $records{ $count }{'ITEM_ID'} || '', + $records{ $count }{'CHRG_LIBRARY'} || '', + $records{ $count }{'CHRG_DC'} || '', + $records{ $count }{'CHRG_DATEDUE'} || '', + ) . "\n"; +} + +print "FORM\tUSER_ID\tITEM_ID\tCHRG_LIBRARY\tCHRG_DC\tCHRG_DATEDUE\n"; + +while (my $line = <>) { + chomp $line; $line =~ s/[\r\n]//g; + if ($line =~ /DOCUMENT BOUNDARY/) { + if (defined $records{ $count }) { + print_line(); + } + $count++; $records{ $count } = {}; + } + if ($line =~ /FORM=(.+)/) { + $records{ $count }{'FORM'} = $1; + } + if ($line =~ /\.USER_ID\..+\|a(.+)/) { + $records{ $count }{'USER_ID'} = $1; + } + if ($line =~ /\.ITEM_ID\..+\|a(.+)/) { + $records{ $count }{'ITEM_ID'} = $1; + } + if ($line =~ /\.CHRG_LIBRARY\..+\|a(.+)/) { + $records{ $count }{'CHRG_LIBRARY'} = $1; + } + if ($line =~ /\.CHRG_DC\..+\|a(.+)/) { + $records{ $count }{'CHRG_DC'} = $1; + } + if ($line =~ /\.CHRG_DATEDUE\..+\|a(.+)/) { + $records{ $count }{'CHRG_DATEDUE'} = $1; + } +} +print_line(); + -- 1.7.2.5