[geeks] script language advice

Jonathan C. Patschke jp at celestrion.net
Sat Feb 2 14:28:59 CST 2008


On Sat, 2 Feb 2008, Nadine Miller wrote:

> num of dupes * filesize  /path/to/file/filename /path/to/file/filename2
> /path/to/filename3 [...]

Ah, the perl code you'd want is something like:

   while (<>) {                              # Snag a line from stdin
         chomp;                              # Trim the line-ending
         my @components = split(/\s/);       # Split into a list at spaces
         my $dupcount   = shift @components; # Remove the first field.
         my $trash1     = shift @components; # Remove the second field.
         my $trash2     = shift @components; # Remove the third field.
         my $fileToKeep = shift @components; # Remove the fourth field.

         unlink @components;                 # Delete everything else.
   }

If you wanted to test this, you could replace the last two lines with:

   print "Keeping $fileToKeep, nuking: ";
   foreach my $filename (@components) { print "$filename," }
   print "\n";

-- 
Jonathan Patschke
Elgin, TX
USA



More information about the geeks mailing list