73 lines
1.3 KiB
Perl
Executable File
73 lines
1.3 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
use strict; use warnings;
|
|
use Getopt::Long;
|
|
|
|
my $newlines = '';
|
|
my $file = '';
|
|
GetOptions ("newlines" => \$newlines, # print newlines
|
|
"file=s" => \$file # input file
|
|
) or die("Error in command line arguments\n");
|
|
|
|
my %seen = ();
|
|
|
|
my $in_file;
|
|
|
|
if ($file) {
|
|
open my $in_file, $file or die "Could not open $file: $!";
|
|
while (my $line = <$in_file>) {
|
|
last if not defined $line;
|
|
chomp $line;
|
|
my @l = $line =~ /([0-9]+\/[0-9]+\/[0-9]+)/mg;
|
|
foreach my $item (@l) {
|
|
$seen{$item}++;
|
|
}
|
|
}
|
|
close $in_file;
|
|
} else {
|
|
for (;;) {
|
|
my $input = <STDIN>;
|
|
last if not defined $input;
|
|
chomp $input;
|
|
my @l = $input =~ /([0-9]+\/[0-9]+\/[0-9]+)/mg;
|
|
foreach my $item (@l) {
|
|
$seen{$item}++;
|
|
}
|
|
}
|
|
}
|
|
|
|
my @uniq = sort gw_comp keys %seen;
|
|
if (@uniq) {
|
|
if ($newlines) {
|
|
foreach my $item (@uniq) {
|
|
print "$item\n";
|
|
}
|
|
} else {
|
|
print "@uniq\n";
|
|
}
|
|
}
|
|
|
|
sub gw_comp{
|
|
# extract $1/$2/$3 for both GAs
|
|
$a =~ /([0-9]+)\/([0-9]+)\/([0-9]+)/;
|
|
my $a1 = $1;
|
|
my $a2 = $2;
|
|
my $a3 = $3;
|
|
$b =~ /([0-9]+)\/([0-9]+)\/([0-9]+)/;
|
|
my $b1 = $1;
|
|
my $b2 = $2;
|
|
my $b3 = $3;
|
|
|
|
if ($a1 < $b1) {
|
|
return -1;
|
|
} elsif ($a1 == $b1) {
|
|
if ($a2 < $b2) {
|
|
return -1;
|
|
}
|
|
elsif($a2 == $b2) {
|
|
return $a3 <=> $b3;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|