R
Rich Grise
I have a collection of about 6000 files that need to be reorganized.
These have been strewn all over the place, from CDs to various partitions
and subdirectories on different workstations, to a pile of various
subdirectories from our Samba server, and what-not.
They're all on different depths of subdir, and I'm almost certain that
there's a lot of redundancy - I've got a list that looks something like
this example:
/Collection/a/b/c/d/file1
/Collection/a/b/c/d/file2
/Collection/a/b/c/d/file3
/Collection/a/b/c/d/file4
/Collection/a/b/c/e/file4
/Collection/a/b/c/e/file5
/Collection/e/f/g/file4
/Collection/e/f/g/file5
/Collection/e/f/g/file6
/Collection/e/f/g/file7
and so on; as you can see, they're at different subdir depths;
what I want to do, if possible, is to take this array, split out
only the last component (after some unknown number of '/', but
the last one in the string), put it in the front of a new
string, then concatenate the original line;
The ultimate goal is to sort these by filename - I could kill
a lot of reduncancy pretty easy that way.
But it turns out, what I've been trying to do is use
for (<>) {
my @line = split(/\//,$_);
my $count = @line;
print (@line[$count-1], " : ", $_);
}
doesn't seem to accomplish what I think it should. Here's the
script I've got so far:
#!/usr/bin/perl
while (<>) {
$input = chop($_);
@line = split(/\//,$input);
$count = @line;
print ("count = ", $count, "\n");
# foreach $item(@line) {
# print (" item = ", $item);
# }
# print ("count = ", $count, " ");
# for ($i = 0; $i < $count; $i++) {
# print (" item ", $i, " = ", @line[$i], " ");
# }
# $myitem = @line[$count-1];
# print (@line[$count-1]);
# print ": ";
# print $input;
# print "\n";
}
As you can seem I've tried variations on this, and nothing I've
tried yet has done what I want.
Here's the input (example):
/Collection/a/b/c/d/file1
/Collection/a/b/c/d/file2
/Collection/a/b/c/d/file3
/Collection/a/b/c/d/file4
/Collection/a/b/c/e/file4
/Collection/a/b/c/e/file5
/Collection/e/f/g/file4
/Collection/e/f/g/file5
/Collection/e/f/g/file6
/Collection/e/f/g/file7
And here's what I want the output to look like:
file1 : /Collection/a/b/c/d/file1
file2 : /Collection/a/b/c/d/file2
file3 : /Collection/a/b/c/d/file3
file4 : /Collection/a/b/c/d/file4
file4 : /Collection/a/b/c/e/file4
file5 : /Collection/a/b/c/e/file5
file4 : /Collection/e/f/g/file4
file5 : /Collection/e/f/g/file5
file6 : /Collection/e/f/g/file6
file7 : /Collection/e/f/g/file7
Which I could sort, and track down the duplicates.
But I'm stuck on rearranging the strings. )-;
Would anyone wish to be so kind as to volunteer to do my homework for me?
Thanks,
Rich
These have been strewn all over the place, from CDs to various partitions
and subdirectories on different workstations, to a pile of various
subdirectories from our Samba server, and what-not.
They're all on different depths of subdir, and I'm almost certain that
there's a lot of redundancy - I've got a list that looks something like
this example:
/Collection/a/b/c/d/file1
/Collection/a/b/c/d/file2
/Collection/a/b/c/d/file3
/Collection/a/b/c/d/file4
/Collection/a/b/c/e/file4
/Collection/a/b/c/e/file5
/Collection/e/f/g/file4
/Collection/e/f/g/file5
/Collection/e/f/g/file6
/Collection/e/f/g/file7
and so on; as you can see, they're at different subdir depths;
what I want to do, if possible, is to take this array, split out
only the last component (after some unknown number of '/', but
the last one in the string), put it in the front of a new
string, then concatenate the original line;
The ultimate goal is to sort these by filename - I could kill
a lot of reduncancy pretty easy that way.
But it turns out, what I've been trying to do is use
for (<>) {
my @line = split(/\//,$_);
my $count = @line;
print (@line[$count-1], " : ", $_);
}
doesn't seem to accomplish what I think it should. Here's the
script I've got so far:
#!/usr/bin/perl
while (<>) {
$input = chop($_);
@line = split(/\//,$input);
$count = @line;
print ("count = ", $count, "\n");
# foreach $item(@line) {
# print (" item = ", $item);
# }
# print ("count = ", $count, " ");
# for ($i = 0; $i < $count; $i++) {
# print (" item ", $i, " = ", @line[$i], " ");
# }
# $myitem = @line[$count-1];
# print (@line[$count-1]);
# print ": ";
# print $input;
# print "\n";
}
As you can seem I've tried variations on this, and nothing I've
tried yet has done what I want.
Here's the input (example):
/Collection/a/b/c/d/file1
/Collection/a/b/c/d/file2
/Collection/a/b/c/d/file3
/Collection/a/b/c/d/file4
/Collection/a/b/c/e/file4
/Collection/a/b/c/e/file5
/Collection/e/f/g/file4
/Collection/e/f/g/file5
/Collection/e/f/g/file6
/Collection/e/f/g/file7
And here's what I want the output to look like:
file1 : /Collection/a/b/c/d/file1
file2 : /Collection/a/b/c/d/file2
file3 : /Collection/a/b/c/d/file3
file4 : /Collection/a/b/c/d/file4
file4 : /Collection/a/b/c/e/file4
file5 : /Collection/a/b/c/e/file5
file4 : /Collection/e/f/g/file4
file5 : /Collection/e/f/g/file5
file6 : /Collection/e/f/g/file6
file7 : /Collection/e/f/g/file7
Which I could sort, and track down the duplicates.
But I'm stuck on rearranging the strings. )-;
Would anyone wish to be so kind as to volunteer to do my homework for me?
Thanks,
Rich