Well, I don't know if this is exactly what you were looking for, but  
hopefully it's at least enough to get you started.

You can run it with:  perl convert.pl IN_FILE >OUT_FILE

I couldn't see how the Feature, Modification Date, and Last Modified  
fields were being used in the new format, so this version doesn't use  
them.  They would be trivial to add, if you did want them though (add  
to %columns for the first two and/or modify the last split for the  
other).

This script doesn't quote CSV fields that need it.  None of your  
example fields did, but if others might, you'll have to add it.

Good luck with your conversion.

James

#!/usr/bin/perl

use 5.6.0;
use strict;
use warnings;

my %columns = ( 'Author'                        => 1,
                                'Number'                        => 5,
                                'Version Number'        => 4,
                                'File Name'                     => 0 );

my $header = 1;
my @row = ('', '', '', '', '', '', '', '', '');
while (<>) {
        if ($header) {
                my($name, $value) = split /:/, $_;
                if ($value) {
                        $name =~ s/\s*$//;
                        $value =~ s/^\s*(.+?)\s*$/$1/;
                        $row[ $columns{$name} ] = $value if exists $columns{$name};
                }
                else {
                        $header = 0;
                        print "File Name,Author,Date (MM/DD/Year),",
                                  "Time (H:M:S),Version No.,Number,",
                                  "Feature Name,Paragraph Number,Requirement Number\n";
                }
        }
        else {
                (@row[7, 8], undef) = split;
                print join(',', @row) . "\n";
        }
}

On Wednesday, October 16, 2002, at 03:50  AM, pelp wrote:

> Yahoo! is acting funny.
>
> http://www.geocities.com/pelpme/current_format.txt (original file)
> http://www.geocities.com/pelpme/csv.htm (new format)
>
>
>
>
> On Wed, 16 Oct 2002 03:10:12 UT, "pelp" <[EMAIL PROTECTED]> said:
>> This is the correct link to the CSV file,
>> http://us.f1.yahoofs.com/users/593a164/bc/sample/ 
>> csv.htm?bchPOr9A0FpGqXUN
>>
>>
>>
>> On Wed, 16 Oct 2002 02:55:34 UT, "pelp" <[EMAIL PROTECTED]> said:
>>> I need some much needed help to do some data munging. I come from a  
>>> C++
>>> background (3+ years) and have little experience with PERL (about 2
>>> months). At work today I was given a task to convert 1300+ logs to a  
>>> new
>>> format, and the program is due tomorrow (i know.. how nice?)!!!
>>>
>>> Currently a log is defined in this format
>>> [http://us.f1.yahoofs.com/users/593a164/bc/sample/ 
>>> current_format.txt?bcecNr9AYfCpF3LW]
>>> and needs to be converted to a CSV file in this format
>>> [http://us.f1.yahoofs.com/users/593a164/bc/sample/ 
>>> csv.htm?bcecNr9A7uS5stoy]
>>>
>>> As of right now, I'm stuck of how to extract each token from the old
>>> format and convert it to the new format such as the values of author,
>>> number , version number. I've tried to find some sample code on the  
>>> NET
>>> including this site but was unable.
>>>
>>> Please bless me with some PERL wisdom to get me started on this. I  
>>> will
>>> greatly apprecitiate any help that I get.
>>>
>>> Thanks ahead.
>>>
>>> -- 
>>> http://fastmail.fm/ - IMAP accessible web-mail
>>
>> -- 
>> http://fastmail.fm/ - IMAP accessible web-mail
>>
>
> -- 
> http://fastmail.fm - Email service worth paying for. Try it for free
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to