Skip to content

Instantly share code, notes, and snippets.

@mash
Created February 22, 2009 09:28
Show Gist options
  • Save mash/68416 to your computer and use it in GitHub Desktop.
Save mash/68416 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use Encode;
use utf8;
use File::Slurp;
#my $file = 'template2.csv';
my $file = '0222.1.csv';
my @lines = read_file( $file );
my @new_lines = ('名前,メール アドレス,メモ,セクション 1 - 説明,セクション 1 - メール,セクション 1 - IM,セクション 1 - 電話番号,セクション 1 - 携帯電話,セクション 1 - ポケットベル,セクション 1 - FAX,セクション 1 - 会社名,セクション 1 - 役職,セクション 1 - その他,セクション 1 - 住所');
for my $line (@lines[1..$#lines]) {
$line = Encode::decode( 'cp932', $line );
my @columns = split(/,/, $line);
my $name = $columns[1];
$name =~ s/[" ]*//g; # 全角空白
my $phone = $columns[3];
my $email = $columns[4];
my $phone2 = $columns[12];
my $email2 = $columns[13];
push( @new_lines, Encode::encode_utf8("\"$name\",$email,,Personal,,,,$phone,,,,,,\n") );
push( @new_lines, Encode::encode_utf8("\"${name}2\",$email2,,Personal,,,,$phone2,,,,,,\n") ) if ( $phone2 or $email2 );
}
write_file( 'output.csv', @new_lines );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment