Tzafrir Cohen wrote:
> Anyway, numbers are pure ascii. Unless you use a character for the
> hiphen that is not the standard ascii hiphen-minus ('-'), the whole
> string is ascii, and thus any standard text manipulation tools should be
> able to handle it, even if they don't support UTF-8 .
Enclosed is a perl script I wrote (in simple easy to follow code) that
reads a file exported by morotola phone tools, and converts it. The
actual conversion is done in a subroutine that can be used elsewhere.
Geoff.
--
Geoffrey S. Mendelson [EMAIL PROTECTED]
#!/usr/bin/perl
sub fix_number
{
$old = @_[0];
$fixme = 0;
#
# Skip blank numbers
#
if ($old eq "\"\"")
{
return "\"\"";
}
#
# Get prefix
#
$prefix = substr($old,0,1);
if ($prefix eq "\"")
{
$l = length($old);
$l = $l - 2;
$old = substr($old,1,$l);
$prefix = substr($old,0,1);
}
#
# + prefix GSM international calling
#
if ($prefix eq "+")
{
$fixme = 1;
}
#
# 0 prefix, local Israeli calls.
#
if($prefix eq "0")
{
$fixme = 1;
#
# Exception: 00 or 01, long format long distance or
# non default carrier.
#
if (substr($old,0,2) eq "00) {$fixme = 0;}
if (substr($old,0,2) eq "01) {$fixme = 0;}
}
if (!$fixme)
{
return $old;
}
printf("fix_number called with %s\n",$old);
#
# Parse number into area code and phone number.
#
if ($prefix eq "+")
{
$country_code = substr($old,1,3);
if ($country_code ne "972")
{
return $old;
}
$area_code = "0" . substr($old,4,1);
$number = substr($old,5);
if ($area_code eq "05")
{
$area_code = substr($old,4,2);
$number = substr($old,6);
}
}
else
{
$area_code = substr($old,0,2);
$number = substr($old,2);
if ($area_code eq "05")
{
$area_code = substr($old,1,2);
$number = substr($old,3);
}
}
#
# assume new number is the same as the old, convert to GSM international
# format.
#
$new = "+972" . substr($area_code,1,1) . $number;
printf("area code %s number %s\n",$area_code,$number);
#
# Cell phone numbers must change, fix them and force GSM format.
#
# What do I do with 060-063?
#
#
if ($area_code eq "50" )
{
$new = "+972505" . $number;
}
if ($area_code eq "51" )
{
$new = "+972507" . $number;
}
if ($area_code eq "52" )
{
$new = "+972522" . $number;
}
if ($area_code eq "53" )
{
$new = "+972523" . $number;
}
if ($area_code eq "54" )
{
$new = "+972544" . $number;
}
if ($area_code eq "55" )
{
$new = "+972545" . $number;
}
if ($area_code eq "56" )
{
$new = "+972506" . $number;
}
if ($area_code eq "57" )
{
$new = "+972577" . $number;
}
if ($area_code eq "58" )
{
$new = "+972528" . $number;
}
if ($area_code eq "59" )
{
$new = "+972599" . $number;
}
if ($area_code eq "60" )
{
$new = "+97260" . $number;
}
if ($area_code eq "61" )
{
$new = "+97261" . $number;
}
if ($area_code eq "62" )
{
$new = "+97262" . $number;
}
if ($area_code eq "63" )
{
$new = "+97263" . $number;
}
if ($area_code eq "64" )
{
$new = "+972524" . $number;
}
if ($area_code eq "65" )
{
$new = "+972525" . $number;
}
if ($area_code eq "66" )
{
$new = "+972546" . $number;
}
if ($area_code eq "67" )
{
$new = "+972547" . $number;
}
if ($area_code eq "68" )
{
$new = "+972508" . $number;
}
printf("new %s\n",$new);
return "\"" . $new . "\"";
}
open IN,"pb041404.txt";
open OUT, ">newpb.txt";
#
# Read parse and reassemble Motorola mobile phone tools format.
#
for (;!eof(IN);)
{
$line = <IN>;
chomp $line;
$l = length($line);
if ($l == 0) {next;}
@fields = split(',',$line);
$TITLE = @fields[0];
$FIRSTNAME = @fields[1];
$MIDDLENAME = @fields[2];
$LASTNAME = @fields[3];
$COMPANY = @fields[4];
$ADDRESS_B = @fields[5];
$ZCODE_B = @fields[6];
$CITY_B = @fields[7];
$COUNTRY_B = @fields[8];
$REGION_B = @fields[9];
$JOBTITLE = @fields[10];
$DPT = @fields[11];
$TEL_RD = fix_number(@fields[12]);
$TEL_DIR = fix_number(@fields[13]);
$FAX_B = fix_number(@fields[14]);
$MODEM = fix_number(@fields[15]);
$EXTENSION = fix_number(@fields[16]);
$BBS = fix_number(@fields[17]);
$PAGER = fix_number(@fields[18]);
$CELL_B = fix_number(@fields[19]);
$EMAIL_B = @fields[20];
$URL_B = @fields[21];
$ADDRESS_D = @fields[22];
$ZCODE_D = @fields[23];
$CITY_D = @fields[24];
$COUNTRY_D = @fields[25];
$STATE_D = @fields[26];
$TEL_D = fix_number(@fields[27]);
$FAX_D = fix_number(@fields[28]);
$CELL_D = fix_number(@fields[29]);
$EMAIL_D = @fields[30];
$URL_D = @fields[31];
$USER_1 = @fields[32];
$USER_2 = @fields[33];
$USER_3 = @fields[34];
$NOTES = @fields[35];
$PRIVATEID = @fields[36];
$IPADDRESS = @fields[37];
$OTHER = @fields[38];
$out = $TITLE . "," . $FIRSTNAME . "," . $MIDDLENAME . "," .
$LASTNAME . "," . $COMPANY . "," . $ADDRESS_B . "," .
$ZCODE_B . "," . $CITY_B . "," . $COUNTRY_B . "," .
$REGION_B . "," . $JOBTITLE . "," . $DPT . "," .
$TEL_RD . "," . $TEL_DIR . "," . $FAX_B . "," .
$MODEM . "," . $EXTENSION . "," . $BBS . "," .
$PAGER . "," . $CELL_B . "," . $EMAIL_B . "," .
$URL_B . "," . $ADDRESS_D . "," . $ZCODE_D . "," .
$CITY_D . "," . $COUNTRY_D . "," . $STATE_D . "," .
$TEL_D . "," . $FAX_D . "," . $CELL_D . "," .
$EMAIL_D . "," . $URL_D . "," . $USER_1 . "," .
$USER_2 . "," . $USER_3 . "," . $NOTES . "," .
$PRIVATEID . "," . $IPADDRESS . "," . $OTHER;
printf OUT ("%s\n",$out);
}
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]