I was able to clean up my file as expected but there is one piece I am having trouble with. I want to capture a header in the file and include it into each line copied, (BAR.COMP) and when it gets to the next header if the name changes I want it to include the new header to the next copied lines. This is what I have so far but just confused on how to incorporate the second peice. Any help would be great! Thanks!

use strict; use warnings; open (NEW, ">", "output.txt" ) or die "could not open:$!"; open (FILE, "<", "Report.txt") or die "could not open:$!"; while (<FILE>) { print NEW if /^\h{3}\d/; } close (FILE); close (NEW);

Report.txt

BAR.COMP1 DATE: 12/14/15 G2,,,,,,,USER LOGS DEVICE EMULATOR FROM-THRU MINS ROUTINE G1,,,,,,,USER LOGS COMPUTER04.1 0726 0808 42 Process Account Account Name Master Patient Number Account Number 0727 JOHN DOE 1234567899 1234567899 0730 JOHN DOE 1234567899 1234567897 0732 JOHN DOE 1234567899 1234567899 0742 JOHN DOE 1234567899 1234567893 0744 JOHN DOE 1234567899 1234567893 BAR.COMP2 DATE: 12/14/15 G2,,,,,,,USER LOGS DEVICE EMULATOR FROM-THRU MINS ROUTINE G1,,,,,,,USER LOGS COMPUTER04.1 0726 0808 42 Process Account Account Name Master Patient Number Account Number 0727 JOHN DOE 1234567899 1234567899 0730 JOHN DOE 1234567899 1234567897 0732 JOHN DOE 1234567899 1234567899 0742 JOHN DOE 1234567899 1234567893 0744 JOHN DOE 1234567899 1234567893

output.txt

BAR.COMP1 0727 JOHN DOE 1234567899 1234567899 BAR.COMP1 0730 JOHN DOE 1234567899 1234567897 BAR.COMP1 0732 JOHN DOE 1234567899 1234567899 BAR.COMP1 0742 JOHN DOE 1234567899 1234567893 BAR.COMP1 0744 JOHN DOE 1234567899 1234567893 BAR.COMP2 0727 JOHN DOE 1234567899 1234567899 BAR.COMP2 0730 JOHN DOE 1234567899 1234567897 BAR.COMP2 0732 JOHN DOE 1234567899 1234567899 BAR.COMP2 0742 JOHN DOE 1234567899 1234567893 BAR.COMP2 0744 JOHN DOE 1234567899 1234567893

In reply to Copy Lines After Match **UPDATE** by jalopez453

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.