2009-03-13 00:03:10 7599171 2639128 6480404 2639 0023
2009-03-13 00:03:14 48020 4478014 2341060 4478 0182
2009-03-13 00:03:17 44476 4916057 2620157 4917 0000
what im hoping to do is to write a perl script that will remove the whitespaces and replace with a , delimiter so that it looks like this:-
2009-03-13,00:03:10,7599171,2639128,6480404,2639,002
2009-03-13,00:03:14,48020,4478014,2341060,447,0182
2009-03-13,00:03:17,44476,4916057,2620157,4917,0000
The perl script should be able to process this file in a directory say /jumbo/in and once the file is processed it should be moved to /jumbo/out
Attached is my perl script that i have come up with needless to say it doesnt work:-
Code:
#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
my @files=</jumbo/in/'>;
while ( <*.txt> ){
open (FH,$_) or die "failed to read $_: $!";
while(my $line = <FH>){
open(OUT,">>" ,"temp") or die "failed open temp for write' $!";
@bits = split(/\s+/,$line);
for ($i=0;$i < $#bits;$i++)
{
if ($i < 5 ) { print "$bits[$i],"; }
else { print "$bits[$i] "; }
}
print OUT $line;
close(FH);
close(OUT);
move("temp","/jumbo/out/".$_) or die "cannot rename temp:$!\n";
unlink $_ or die "Cannot remove $_:$!\n";
}
}

