Urgent Help with Large Text File

Hi All!

I am in need of some urgent help writing a Perl script to rearrange a large text file.  I've attached a sample (prior) of our text file and another file that show what I am hoping end up with.  

any help would be greatly appreciated as our Perl programmer has left the company and this fell into my lap.  

spudmcc
test.TXT
TEST1.xls
spudmccAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Adam314Connect With a Mentor Commented:

open(my $in, "<before.txt") or die "Could not open before: $!\n";
open(my $out, ">after.txt") or die "Could not open after: $!\n";
my ($a, $b, $c);
while(<$in>) {
	chomp;
	s/^\s*//;
	s/\s*$//;
	if(/\.\d+$/) {
		#record data
		my @f=split/\//;
		foreach my $r (@f) {
			print $out join(",",$a,$b,$c,$r) . "\n";
		}
	}
	elsif(m|^\s*(\S+)\s+(.*?)\s+(\d+/\d+/\d+)\s*$|) {
		#header with date
		($a,$b,$c)=($1,$2,$3);
	}
	elsif(m|^(\S+)\s+(.*)$|) {  #\s+ \s+
		($a,$b,$c)=($1,$2,'');
	}
}
close($in);
close($out);

Open in new window

0
 
Adam314Commented:
How should lines with no date be processed (eg: line 16, 26, 41)?
0
 
spudmccAuthor Commented:
Should be treated as null.  Not every record has a date but when available we need to include it.  

Thanks


0
 
spudmccAuthor Commented:
Thank you SO MUCH!  It worked perfect!  I appreciate your time, patience and talent and thank you so much!

Andy (spudmcc)
0
All Courses

From novice to tech pro — start learning today.