Skip to content

Instantly share code, notes, and snippets.

@orenhe
Created June 16, 2012 20:03
Show Gist options
  • Save orenhe/2942388 to your computer and use it in GitHub Desktop.
Save orenhe/2942388 to your computer and use it in GitHub Desktop.
Add phone number prefix to contacts csv: pad phones with zero unless they start with 1
#!/usr/bin/perl -w
# Gets a contacts csv file through stdin, prints to stdout a modified file with phone prefix fixed
# This was useful for me when I exported Nokia contacts, which lacked the first '0' character.
# Note that it ruins the first (head) line, I manually took it from original file, although it must be dead simple to fix it in code.
while (<STDIN>) {
@a=split(",");
foreach ($item = 30; $item < 45; $item++) {
$phone=$a[$item];
if (length($phone) >=8 && substr($phone, 0, 1) != "1") {
$a[$item] = "0".$phone; $_ = join(",", @a)
}
};
print $_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment