重复内容删除的小脚本
2012-12-28 21:32
197 查看
加入说序列式这样的
1 2
1 2
2 1
1 3
1 4
1 5
4 1
我们得出的结果如下:
1 3
1 5
2 1
4 1
程序如下:
use strict;
use warnings;
my $filename;
my %hash;
my @information;
my $key1;
my $key2;
print "please put in the file like this f:\\\\perl\\\\data.txt\n";
chomp($filename=<STDIN>);
open(IN,"$filename")||die("can not open");
while(<IN>)
{
chomp;
@information=split/\s+/,$_;
if(exists $hash{$information[0]}{$information[1]})
{
next;
}
else
{
$hash{$information[0]}{$information[1]}='A';
}
}
close IN;
open(IN,"$filename")||die("can not open");
while(<IN>)
{
@information=split/\s+/,$_;
if(exists $hash{$information[1]}{$information[0]})
{
delete $hash{$information[0]}{$information[1]}
}
else
{
next;
}
}
close IN;
open(OUT,">f:\\A_B_result.txt")||die("can not open");
foreach $key1 (sort{$a<=>$b} keys %hash)
{
foreach $key2 (sort{$a<=>$b} keys %{$hash{$key1}})
{
print OUT "$key1 $key2\n";
}
}
close OUT;
1 2
1 2
2 1
1 3
1 4
1 5
4 1
我们得出的结果如下:
1 3
1 5
2 1
4 1
程序如下:
use strict;
use warnings;
my $filename;
my %hash;
my @information;
my $key1;
my $key2;
print "please put in the file like this f:\\\\perl\\\\data.txt\n";
chomp($filename=<STDIN>);
open(IN,"$filename")||die("can not open");
while(<IN>)
{
chomp;
@information=split/\s+/,$_;
if(exists $hash{$information[0]}{$information[1]})
{
next;
}
else
{
$hash{$information[0]}{$information[1]}='A';
}
}
close IN;
open(IN,"$filename")||die("can not open");
while(<IN>)
{
@information=split/\s+/,$_;
if(exists $hash{$information[1]}{$information[0]})
{
delete $hash{$information[0]}{$information[1]}
}
else
{
next;
}
}
close IN;
open(OUT,">f:\\A_B_result.txt")||die("can not open");
foreach $key1 (sort{$a<=>$b} keys %hash)
{
foreach $key2 (sort{$a<=>$b} keys %{$hash{$key1}})
{
print OUT "$key1 $key2\n";
}
}
close OUT;
相关文章推荐
- SQL语句 删除表user 中字段name 内容重复的记录,
- 删除重复内容行
- 删除重复文件的脚本代码
- 常规版中,重复执行同一脚本,根据变量内容做不同操作。
- mysql 删除数据库title重复内容
- AngularJS,实现输入框失焦添加内容到最前,当数据重复删除原来并显示在数组最前
- 《Advanced Bash-scripting Guide》学习(三):自删除脚本和自读取内容的脚本
- 优化网站设计(十二):删除重复脚本
- sed删除文件中的一行内容的脚本代码
- SQL查询和删除重复字段的内容
- Python 脚本 批量删除目录下文件的特定内容
- 日常脚本二——重复数据删除
- 删除内容相同的文件并保留一份副本的shell脚本
- mysql 删除字段内的重复内容只保留一条
- sqlsever 删除字段内容重复数据
- vector erase 重复删除容器内的指定内容时,使用迭代器(iterator)++的操作应该放到For循环内
- SQL 两张完全相同表,删除重复内容
- 使用EditPlus和批处理删除文本重复内容行
- 使用python读取txt文件的内容,并删除重复的行数