On 24/06/2011 08:45, Wernher Eksteen wrote:
> Hi,
>
> I've attached a text file containing the original and required
> format and avoid the format being lost by just pasting it in the
> email body.
>
> The original format is separated by a space, but need to replace the
> space with a comma, so it will become a comma delimited csv file
> which I will then import to MS Excel.
>
> I'm not sure how to parse the "Connection" and "Sync'ed-as-of-time"
> columns since the dates there in is in this format "Fri Jun 24 06:37"
> which also separated by space, but the spaces in those columns
> shouldn't be replaced by a comma. The date format in those columns
> should remain the same.
>
> Also, is it possible to convert this directly into a MS Excel document
> using Perl?

Hey Wernher

Your data appears to have three or more spaces separating the data
fields, whereas there is never more than a single space within the data.
If that is always the case, and there are never any blank fields, we can
use it to split the line into fields.

Take a look at the program below.

HTH,

Rob


use strict;
use warnings;

while (my $record = <DATA>) {
  chomp $record;
  my @fields = split /[ ]{3,}/, $record;
  print join ',', @fields;
  print "\n";
}

__DATA__
CTX   Destination                                                             
Enabled   Connection         Sync'ed-as-of-time
---   ---------------------------------------------------------------------   
-------   ----------------   ------------------
1     pool://ZABRYDD01.localdomain/RDP_NEW_REP                                
yes       Sat Jun 18 08:56   Fri Jun 24 06:37
2     dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test101    
yes       Sat Jun 18 08:57   Fri Jun 24 08:01
4     dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test22     
yes       Sat Jun 18 08:57   Fri Jun 24 09:00
5     pool://ZARDPDD01.localdomain/BRYREP                                     
yes       Sat Jun 18 08:57   Fri Jun 24 07:01
8     dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test31     
yes       Sat Jun 18 08:57   Fri Jun 24 09:00
10    dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test421    
yes       Sat Jun 18 08:57   Fri Jun 24 09:00
12    dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test5      
yes       Sat Jun 18 08:57   Fri Jun 24 09:00
13    dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test60     
yes       Sat Jun 18 08:57   Fri Jun 24 09:00
---   ---------------------------------------------------------------------   
-------   ----------------   ------------------

**OUTPUT**

CTX,Destination,Enabled,Connection,Sync'ed-as-of-time
---,---------------------------------------------------------------------,-------,----------------,------------------
1,pool://ZABRYDD01.localdomain/RDP_NEW_REP,yes,Sat Jun 18 08:56,Fri Jun 24 06:37
2,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test101,yes,Sat 
Jun 18 08:57,Fri Jun 24 08:01
4,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test22,yes,Sat 
Jun 18 08:57,Fri Jun 24 09:00
5,pool://ZARDPDD01.localdomain/BRYREP,yes,Sat Jun 18 08:57,Fri Jun 24 07:01
8,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test31,yes,Sat 
Jun 18 08:57,Fri Jun 24 09:00
10,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test421,yes,Sat 
Jun 18 08:57,Fri Jun 24 09:00
12,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test5,yes,Sat 
Jun 18 08:57,Fri Jun 24 09:00
13,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test60,yes,Sat 
Jun 18 08:57,Fri Jun 24 09:00
---,---------------------------------------------------------------------,-------,----------------,------------------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to