去除文件中重复行,保序perl代码。
2015-05-09 17:26
176 查看
#!/usr/bin/perl #get scripts name #print $0 . "\n"; #get the parameters my $argc = $#ARGV+1; my $src_file; my $dst_file; #print "$argc\n"; if($argc == 2) { $src_file = @ARGV[0]; $dst_file = @ARGV[1]; } elsif ($argc == 1) { $src_file = @ARGV[0]; $dst_file = @ARGV[0]."_tmp"; } else { die "error, <src_file> [dst_file]"; } my $RD_FILE; my $WR_FILE; my $line_str; my %hash; open ($RD_FILE ,"<$src_file") || die "Cannot open file $!"; open ($WR_FILE ,">$dst_file") || die "Cannot open file $!"; while($line_str = <$RD_FILE>){ chomp($line_str); if(!($line_str =~ /^\s?$/)){ if(! $hash{$line_str}){ #print "$line_str\n"; print $WR_FILE "$line_str\n"; $hash{$line_str} = 1; } } } close($RD_FILE); close($WR_FILE); print "The $dst_file file has generated.\n";
相关文章推荐
- perl脚本去除文件中重复数据
- 使用perl清理电脑上重复文件实现代码(续)
- perl去除重复内容的脚本代码(重复行+数组重复字段)
- python文件去除重复的代码示例
- 去除文件中的重复行
- python去除文件中重复的行实例
- 最全的用正则批量去除Teleport Pro整站下载文件冗余代码
- (Java 功能代码)java去除List中重复数据之Object对象
- Java编写去除代码文件中的注释以及空格、换行,并写入目标文件中
- [置顶] PHP批量检测并去除文件BOM头代码实例 导致空白行解决办法
- 去除java的泛型集合(字符串)重复元素参考代码
- android 音乐文件重复播放的代码
- 去除整站下载文件中的tppabs等冗余代码
- 去除List集合中的重复对象,Map遍历代码
- perl从文件中读取数据并输出的实现代码
- List ADD时去除重复对象代码
- Perl 使用 sort, hash解析文件代码
- 在windows下解压缩Linux内核源代码出现重复文件原因
- PHP上传文件代码练习2 (重复文章)