56 lines
1.1 KiB
Perl
56 lines
1.1 KiB
Perl
|
#!/usr/bin/perl
|
|||
|
|
|||
|
# Usuwa zb<7A>dne powt<77>rzenia scie<69>ek
|
|||
|
|
|||
|
use locale;
|
|||
|
|
|||
|
#if (@ARGV < 1) {
|
|||
|
# print "USAGE: remDup.pl num\n\tGdzie \"num\" jest ilo<6C>ci<63> powt<77>rze<7A>, kt<6B>re zostawiamy\n";
|
|||
|
# exit(0);
|
|||
|
#}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#ilo<6C><6F> powt<77>rze<7A>, kt<6B>re zostawiamy
|
|||
|
$max = 10;
|
|||
|
|
|||
|
# przyjmujemy, ze na wej<65>ciu znajduje si<73> plik posortowany,
|
|||
|
# po ko<6B>c<EFBFBD>wkach oraz po prawdopodobie<69>stwie
|
|||
|
|
|||
|
$line = <>;
|
|||
|
|
|||
|
while (($line !~ m/^$/) || ($line =~ m/^\n$/)) {
|
|||
|
|
|||
|
$count = 0;
|
|||
|
|
|||
|
while ($line =~ m/^\n$/) {
|
|||
|
$line = <>;
|
|||
|
}
|
|||
|
|
|||
|
$line =~ /^([^~]+)~.*/;
|
|||
|
$theEnd = $1;
|
|||
|
$end = $1;
|
|||
|
|
|||
|
while (($end =~ m/$theEnd/) && ($count++ < $max)) {
|
|||
|
print $line;
|
|||
|
$line = <>;
|
|||
|
$line =~ /^([^~]+)~.*/;
|
|||
|
$end = $1;
|
|||
|
}
|
|||
|
|
|||
|
# tutaj mamy dwie mo<6D>liwo<77>ci:
|
|||
|
# 1. wypisali<6C>my ju<6A> max lini - musimy wywali<6C> kolejne linie, kt<6B>re
|
|||
|
# zawieraj<61> ko<6B>c<EFBFBD>wk<77> theEnd,
|
|||
|
# 2. pasuj<75>cych lini by<62>o mniej ni<6E> max, wtedy nic nie musimy robi<62>
|
|||
|
# - w zmiennej line znajduje si<73> kolejna linia...
|
|||
|
|
|||
|
if ($count == $max + 1) {
|
|||
|
while ($oldEnd =~ m/$theEnd/) {
|
|||
|
$line = <>;
|
|||
|
$line =~ /^([^~]+)~.*/;
|
|||
|
$oldEnd = $1;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|