Hi All,
I have a file that has records for the same unique ID on multiple line
+s.
Sample:
A02545142 CA0 0120000612A02545142 C 00000000 G
+
A02545142 CA3 0120080804 121303 USEDT
+
A02545142 CD0 01GENERALI HOLDING VIENNA AG ORD
+
A02545142 CD1 01OUTFC 000000 29GRHVF 000000000000 YNN
+ AT NATN
A02545142 CD2 010000000000000000000000 00000000000000 F
+
A02545142 CD3 01 00000000000000 00000000
+
A02545142 CE0 01 0000000000000000000 00000000000000
+
A02545142 CE1 0100000000 00000000 00000000 00
+000000
A02545142 CI0 0100000000000000000000000000000000 00000000000000
+0000000000
A02545142 CR1 01 00000000 00000000 00000000
+
A02545142 CT2 01 9920000607AGRHVF
+
A02545142 CX0 01A02545142
+
A02545142 CX3 01 00000000
+
A02545142 CX4 01GRHVF
+
A03987103 CA0 0120030305A03987103 C 00000000 G
+
A03987103 CA3 0120080710 180603 USEDT
+
A03987103 CD0 01AAP IMPLANTATE AG BERLIN AKT
+
A03987103 CD1 01OUTFC 384100 29APIPF 000000000000 YNN
+YAT NATN
A03987103 CD2 010000000000000000000000 00000000000000 F
+
A03987103 CD3 01 00000000000000 00000000
+
A03987103 CD8 01339112 3841
+
A03987103 CE0 01 0000000000000000000 00000000000000
+
A03987103 CE1 0100000000 00000000 00000000 00
+000000
A03987103 CI0 0100000000000000000000000000000000 00000000000000
+0000000000
A03987103 CR1 01 00000000 00000000 00000000
+
A03987103 CT2 01 9920030304AAPIPF
+
A03987103 CX0 01A03987103 009763775 B3BGFP7DE00
+05066609
A03987103 CX3 010220080710F5678220AB28DW53
+
A03987103 CX4 01APIPF
+
The first field of each line denotes the unique ID.
I need to parse each line for data set at a fix width and print it to
+a single line.
Here is what I have so far and it is not working.
while (@ARGV) {
$file=shift (@ARGV);
open (DATA,"$file") || die "unable to open tmp file";
while (defined($Rec = <DATA>)) {
push(@Lines, $Rec);
foreach $line (@Lines) {
if ($line =~ /CA0/) {
$USERNUM = substr($line, 0, 12);
}
if (($line =~ /CA0/) && ($line =~ /^$USERNUM/)) {
$RECTYPE = substr($line, 13, 2);
$ASSET = substr($line, 51, 1) ;
}
if (($line =~ /CX4/) && ($line =~ /^$USERNUM/)) {
$EXTK = substr($line, 18, 33);
}
push(@Recs, "$USERNUM|$RECTYPE|$ASSET|$EXTK");
}
}
}
foreach $X (@Recs) {
($USERNUM, $RECTYPE, $ASSET, $EXTK) = split /\|/, $X;
print "$USERNUM $RECTYPE $ASSET $EXTK\n";
}
Any suggestions or help is deeply appreciated.