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.

In reply to Extracting records with unique ID by mmittiga17

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.