Hi Tom,

I found a script which does this for me which is as follows:-


#!/usr/bin/perl

#open(INFILE,'testJohor1.csv');
#open(OUTFILE,'xyz1.txt');

if (2 != ($#ARGV+1)) {

   print "Usage: $0 <infile> <outfile>\n";
   exit 1;
}

open INFILE,  "<$ARGV[0]" || die "unable to open INFILE";
open OUTFILE, ">$ARGV[1]" || die "unable to open OUTFILE";

while (<INFILE>) {

   if (/(.*)(\d)\/(\d)/) {

   my $stub  = $1;
   my $start = $2;
   my $end   = $3;

   for $i ($start..$end) {

       print OUTFILE "$stub$i\n";
   }

   } else {

     print OUTFILE "$_";
   }
}

close INFILE;
close OUTFILE;

It converts the fields in my input file like 097611/4 to
097611
097612
097613
097614

But there are some of the fields like 09778/0, which should be converted to
09778
09779
09770

The script ignores these values where difit before '/' is greater than the
one which is after that.

Any improvizations??

Thanks,
Mihir

On 6/24/07, Tom Phoenix <[EMAIL PROTECTED]> wrote:

On 6/24/07, Mihir Kamdar <[EMAIL PROTECTED]> wrote:

> I have a csv file having 3rd field as phone number series. In that
field,
> some of the records are phone number ranges like 097611/4
>
> Now I need to seperate this into 4 numbers and store them one after the
> other, like:-
>
> 097611
> 097612
> 097613
> 097614

I recommend writing a Perl program to do this processing. Perl is
excellent at text handling in general, and there are many modules on
CPAN to help with the thornier tasks. Have you tried Perl yet? How far
have you gotten? Where are you stuck?

Cheers!

--Tom Phoenix
Stonehenge Perl Training

Reply via email to