If you don't provide $ARGV[1] (i.e 'remove') on the command line then the code would not enforce removal of any duplicate files...I've changed a little bit in the design of the code to make it easier for me when reading from a fileMD5.txt instead of having to provide for it through $ARGV[0]..

I could not see the reason why a data structure like "$seen{"$md5:$filesize"}" should be used so instead I made the hash key be the filename only, considering that a duplicate file is identified by its name...

The test text file 'fileMD5.txt' contains the following data:

8e773d2546655b84dd 304048 pics/20041004kidscamera/im001020.jpg im +001020.jpg e01d4d804d454dd1fb 296663 pics/20041004kidscamera/im001021.jpg im +001021.jpg 8e773d2546655b84dd 304048 pics/20041004kidscamera/im001020.jpg im +001020.jpg 8e773d2546655b84dd 304048 pics/20041004kidscamera/im001020.jpg im +001020.jpg 8e773d2546655b84dd 304048 pics/20041004kidscamera/im001020.jpg im +001020.jpg 8e773d2546655b84dd 304048 pics/20041004kidscamera/im001020.jpg im +001020.jpg e01d4d804d454dd1fb 296663 pics/20041004kidscamera/im001021.jpg im +001021.jpg e01d4d804d454dd1fb 296663 pics/20041004kidscamera/im001021.jpg im +001021.jpg 8e773d2546655b84dd 304048 pics/20041004kidscamera/im001020.jpg im +001020.jpg 8e773d2546655b84dd 304048 pics/20041004kidscamera/im001020.jpg im +001020.jpg e01d4d804d454dd1fb 296663 pics/20041004kidscamera/im001021.jpg im +001021.jpg e01d4d804d454dd1fb 296663 pics/20041004kidscamera/im001021.jpg im +001021.jpg

Here is just an illustration of a concept that you can incorporate, it gives you a list of unique files on the STDOUT console and a list of those duplicates would be printed onto a temp file, my approach is open for criticism, modification and comments for I am a learner myself, best of luck:

use strict; use warnings; my $fileCNT = 0; my $dupCNT = 0; my $origCNT = 0; my %seen; my %duplicates; open IN,"< fileMD5.txt" or die ".. we don't see a file to read\n"; print " ... starting to read find duplicats in fileMD5.txt.....\n\n\n" +; while(<IN>){ my $line = $_; chomp $line; $fileCNT++; my ($md5,$filesize,$pathfile,$file) = split /\s+/,$line; if(exists $seen{"$file"}){ $dupCNT++; push @{$duplicates{"$file"}}, ([$pathfile,$filesize]); }else{ push @{$seen{"$file"}}, ([$md5,$pathfile,$filesize]); $origCNT++; } } open (TEMP, '>>', "_Duplicate.temp") or die("can not create temporary +file\n"); print TEMP "FilePath",' ' x 40,"File Size\n\n"; for my $key(keys %duplicates){ my $lineNo=1; for my $info(@{$duplicates{$key}}){ print TEMP "@{[$lineNo++]}:@$info\n\n\n"; } } print "\U\t\toriginal files:\E\n\n"; print "FileName",' 'x20,"Location",' 'x 20,"size\n"; print "_" x 70,"\n"; for my $key(keys %seen){ my $lineNo = 1; for my $info(@{$seen{$key}}){ print "@$info\n"; } } print "\n\n\USummary\E:files: $fileCNT originals: $origCNT files dup +licated: $dupCNT.\E\n\n"; #use Data::Dumper; #print Dumper(\%duplicates); #print Dumper(\%seen);

Output to console:

... starting to read find duplicats in fileMD5.txt..... ORIGINAL FILES: FileName Location size ____________________________________________________________________ 8e773d2546655b84dd pics/20041004kidscamera/im001020.jpg 304048 e01d4d804d454dd1fb pics/20041004kidscamera/im001021.jpg 296663 SUMMARY:files: 12 originals: 2 files duplicated: 10.

Output to temp file:

FilePath File Size 1:pics/20041004kidscamera/im001020.jpg 304048 2:pics/20041004kidscamera/im001020.jpg 304048 3:pics/20041004kidscamera/im001020.jpg 304048 4:pics/20041004kidscamera/im001020.jpg 304048 5:pics/20041004kidscamera/im001020.jpg 304048 6:pics/20041004kidscamera/im001020.jpg 304048 1:pics/20041004kidscamera/im001021.jpg 296663 2:pics/20041004kidscamera/im001021.jpg 296663 3:pics/20041004kidscamera/im001021.jpg 296663 4:pics/20041004kidscamera/im001021.jpg 296663


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

In reply to Re^3: Find dup files and display the output of the script in /tmp dir by biohisham
in thread Find dup files and display the output of the script in /tmp dir by anthonyraj75

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.