Here's a script I use to find large files with the same name for pruning
purposes :-
See the if in the wanted() sub. Here it just adds both names+paths to the
output if it's seen the file of the same name previously. It should be
relatively easy to adjust it to product a count ...
if (exists $found{$n[0]})
{
$found{$n[0]}++;
}
else
{
$found{$n[0]} = 1;
}
and then instead of foreach (sort @op ) ... :-
foreach(sort keys %found)
{
print "$found{$_} $_\n";
}
Regards,
Tim
----------------------------------------
use File::Find;
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
die "Usage: perl -w bigdups.pl size(blocks?)\n" if !defined $ARGV[0];
@op = ();
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '.');
foreach ( sort @op )
{
print "$_\n";
}
exit;
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
(int(((-s _) + 511) / 512) > $ARGV[0]) && do {
# print("$name\n");
@n = reverse split /\//, $name;
if (exists $found{$n[0]})
{
push @op, $name . " vs " . $found{$n[0]};
}
else
{
$found{$n[0]} = $name;
}
};
}
----------------------------------------
----- Original Message -----
From: "Ruebel Oliver" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, March 21, 2001 9:13 AM
Subject: Pattern Matching
How can I get through pattern matching an operation that,
if there a two similar lines (I´m searching for) the program counts them
and gives me only one line output with the number of hits in front.
Like when the program founds 2 lines with:
Network Interface Card 10 Mbit
Network Interface Card 10 Mbit
It gives me the output:
2 Network Interface Card 10 Mbit
Thanks in advance!
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl