add simple command line opts
parent
9e2e13f32c
commit
9a95a8add6
44
filter.pl
44
filter.pl
|
@ -1,22 +1,50 @@
|
|||
#!/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 = ();
|
||||
|
||||
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 $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) {
|
||||
print "@uniq\n";
|
||||
if ($newlines) {
|
||||
foreach my $item (@uniq) {
|
||||
print "$item\n";
|
||||
}
|
||||
} else {
|
||||
print "@uniq\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub gw_comp{
|
||||
|
|
Loading…
Reference in New Issue