#!/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";
时间: 2024-12-24 19:58:57