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