Looking for an nice (short & elegant) one liner for the next perl script:
use strict;
use warnings;
my %all;
while(<DATA>) {
chomp;
my ($name, $x, $path) = split /\s+/;
push @{$all{$path}}, $name;
}
foreach my $path (sort keys %all) {
my $cnt = scalar @{$all{$path}};
print "$path $cnt @{$all{$path}}\n" if $cnt > 1;
}
__DATA__
Atxt x a/b/c
Btxt x a/d/x
Ctxt x i/t/a
Dtxt x i/y/a
Etxt x i/t/a
Ftxt x a/d/x
Gtxt x a/d/x
ofc, the one-liner should read from STDIN not from DATA.
In short, the script read 3 fields (name, x, path), and should output summary for duplicated paths in a form: path dup_count name1 ... namex. Each name is different.
So, looking for something like:
my_command | perl -F '\s+' -nle 'shorter_variant_of_the_above_script'
There are probably ways to shorten this, but here’s an attempt:
Output with provided data: