[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Urgent Help with Large Text File

Posted on 2009-05-12
4
Medium Priority
?
206 Views
Last Modified: 2013-11-05
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
0
Comment
Question by:spudmcc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 24368634
How should lines with no date be processed (eg: line 16, 26, 41)?
0
 

Author Comment

by:spudmcc
ID: 24368678
Should be treated as null.  Not every record has a date but when available we need to include it.  

Thanks


0
 
LVL 39

Accepted Solution

by:
Adam314 earned 2000 total points
ID: 24369327

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
 

Author Closing Comment

by:spudmcc
ID: 31580645
Thank you SO MUCH!  It worked perfect!  I appreciate your time, patience and talent and thank you so much!

Andy (spudmcc)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question