- #!/usr/bin/perl -w
- sub usage(){
- print "\\n";
- print "Usage : perl extract_host.pl <filename> <output file>\\n";
- print "\\n";
- }
- sub check($$){
- if($_[0] eq '--help'){
- &usage();
- exit 0;
- }
- if(not $_[0] or not $_[1]){
- &usage();
- exit 1;
- }
- if(not -e $_[0]){
- print "FILE : $ARGV[0] don't exit !\\n";
- exit 1;
- }
- }
- &check($ARGV[0], $ARGV[1]);
- my $file = $ARGV[0];
- my $out = $ARGV[1];
- open(FH, "<$file");
- open(BH, ">$out");
- while(<FH>){
- if($_ =~ s/.*[^\\w\\d]([\\w\\d]+\\-[\\w\\d]+\\-[\\w\\d]+\\.[\\w\\d]+).*/$1/g){
- print BH $_ ;
- }
- }
- close(FH);
- close(BH);
- `cat $out | sort | uniq > $out`;
- print "$out Created !\\n"
- exit 0
- #该片段来自于http://www.codesnippet.cn/detail/240120131920.html
来源: http://www.codesnippet.cn/detail/240120131920.html