Created
May 29, 2010 01:53
-
-
Save pokle/417956 to your computer and use it in GitHub Desktop.
Sort the output of du -h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# Sorts the output of du -h | |
use strict; | |
my $multip = { | |
'G' => 1024*1024*1024, | |
'M' => 1024*1024, | |
'K' => 1024, | |
'B' => 1 | |
}; | |
my $data = []; | |
while(<>) { | |
my $line = $_; | |
if ($line =~ m/^\W*([\d\.]+)([GMKB])\W+(.*)$/) { | |
my $bytes = $1 * $$multip{$2}; | |
push @$data, [$bytes, $line]; | |
} else { | |
print "? $line"; | |
} | |
} | |
my @sorted = sort { | |
$$a[0] <=> $$b[0] | |
} @$data; | |
foreach my $item (@sorted) { | |
print $$item[1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment