teamassociated has asked for the wisdom of the Perl Monks concerning the following question:
Will you offer some help? Thx MUCH!!!!! I am trying to get to this, for every 5 lines of data in the raw file (which is one record), I need to output 6 lines into the output file. Every record should have 'F' be the last line, and 'A' should be the start of the next record. Line F needs to be created for each record and should contain the text 'acctnum=' and then use the first two pieces of data in line A to create the acctnum.
A 5##### 8 Z Axxxx xxxx, ANN 19793.43 02/02/2012 06/08/ +2012 32989.05 B 03###### S JOxxx xxxx, ADxxx .00 xx/xx/xxxx + 0 C 0 7 14## D xxxx ST #101 .00 02/08/2012 06/ +15/2012 NOV D 0 U MILWAUKEE, WI ##### 32989.05 02/08/2012 + 3 E 3##### MILWAUKEE WI .00 53214 + 12 F acctnum=508####8 A 50#### 8 Z ALLEN ,Nxxxxx 75.00 05/27/2012 06/05 +/2012 1845.00 B 037###### E Nxxxx ALLEN .00 09/xx/xxx 06/05/ +2012 MYT####### C 734####### S 15659 XXXX xxxxx .00 06/06/2012 06/1 +4/2012 MYT9##### NOV D 0 C TAYLOR,MI ##### 1845.00 05/27/2012 + 3 3 E 37##### S TAYLOR MI .00 48180 + 3 12 F acctnum=50##### A 50##### 9 Z Axxxx xxxxxx ,SUSETH 75.00 05/05/2012 05/15/2 +012 2045.00 B 0000000000 E SUSE xxxxxxx RIxxx .00 03/18/xxxx 05/15 +/2012 AJT9###### C 313###### 440 xxx xxxx .00 05/16/2012 06/1 +5/2012 AJT9#2###### NOV D 0 C LINCOLN PARK,XX xx### 2045.00 05/05/2012 + 1 3 E 0 S LINCOLN PARK XX .00 481 +46 1 12 F acctnum=50#####
From this: $ cat tstin
0 S LINCOLN PARK MI .00 4 +8146 1 12
My Perl code....been trying and trying....this is like my 5th mod.
use strict; use warnings; my $vers = q|1.5|; my $letter = 'A'; #my $file = qq(/var/adm/scripts/20121106_C1SA_174204.tmp); my $file = qq(/var/adm/scripts/tstin); my ($acctnum,@acctnum); open (my $f, "+<", $file) or die $!; while (my $ln = (<$f>)) { #next if ($. == 1..88); next if $ln !~ /\s\s\s\s\d+.*/; next if $ln =~ /\A\w+|\cM\s\d+\.\d+.*/; substr($ln, 1,2) = ""; substr($ln, 0,1) = $letter++; if ( $. % 5 == 1 ) { ###-- every 5th line --### if ( substr($ln, 10, 4) =~ /\s+/ ) { substr($ln, 10, 4, ""); $acctnum = substr($ln, 2, 10); push @acctnum, "F acctnum=$acctnum"; } } ###-- 79/80 are the 2 spaces not needed --### if ( length(substr($ln, 79, 2)) > 1 || substr($ln, 79, 2) =~ /\s*/ + ) { substr($ln, 79, 2, ""); print $ln; } else { next; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: raw data formatting
by roboticus (Chancellor) on Nov 16, 2012 at 00:24 UTC | |
|
Re: raw data formatting
by Kenosis (Priest) on Nov 16, 2012 at 01:06 UTC | |
by teamassociated (Sexton) on Nov 16, 2012 at 01:45 UTC | |
by Kenosis (Priest) on Nov 16, 2012 at 01:52 UTC | |
by teamassociated (Sexton) on Nov 16, 2012 at 02:24 UTC | |
by Kenosis (Priest) on Nov 16, 2012 at 03:24 UTC | |
|