# double.pl
# 内容 :　重複データ抽出
# 前提 :　重複チェックしたいキーであらかじめソートしておく。
# Copyright (c) 2002-2011 Mitsuo Minagawa, All rights reserved.
# (minagawa@fb3.so-net.ne.jp)
# 使用方法 : c:\>perl double.pl
#
open(IN1,"double.txt");	
open(OUT1,">double_only.txt");	

# 初期値設定
$low_value	=	pack("h8","00000000");	#low-value	
$in1_key	=	$low_value;		#入力キー
$sv_key		=	$low_value;		#1件前の保存キー
$sv_key2	=	$low_value;		#2件前の保存キー
$in1_ctr	=	0;				#入力件数
@save1		=	();				#保存データ

while	($line1	=	<IN1>)				{	
	chomp($line1);	
	$in1_ctr++;	
	my $tmp	=	$line1;
	$tmp	=~	s/(?:\x0D\x0A|[\x0D\x0A])?$/,/;
	@in1	=	map {/^"(.*)"$/ ? scalar($_ = $1, s/""/"/g, $_) : $_}
				($tmp =~ /("[^"]*(?:""[^"]*)*"|[^,]*),/g);
	$in1_key	=	$in1[0];	

	if		($sv_key	eq	$in1_key)		{	
			$out1	=	join(",",@save1);	
			print	OUT1	"$out1\n";	
			$sv_key2	=	$sv_key;	
	}	
	elsif	(($sv_key2	eq	$sv_key)	
		&&	($sv_key	ne	$low_value))	{	
			$out1	=	join(",",@save1);	
			print	OUT1	"$out1\n";	
			print	OUT1	"-" x 80,"\n";	
	}	

	$sv_key		=	$in1_key;	
	@save1		=	@in1;	
}	
if		(($in1_ctr	>	0)	
	&&	($sv_key2	eq	$sv_key))	{	
		$out1	=	join(",",@save1);	
		print	OUT1	"$out1\n";	
}	
close(IN1);	
close(OUT1);	
