Created
June 16, 2012 20:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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