in reply to df output in tabular form using perl

One solution using Text::Table:
#!/usr/bin/perl use warnings; use strict; use Text::Table; use constant CAPACITY => 3; my @lines = `df -hP`; my $header = shift @lines; # Do not create two columns for "Mounted" and "On" $header =~ s/Mounted /Mounted_/; my $table = Text::Table->new(split ' ', $header); { no warnings 'numeric'; # Ignore % signs @lines = sort { $a->[CAPACITY] <=> $b->[CAPACITY] } map [split ' ', $_], @lines; } $table->load(@lines); print $table;
In my systems, Capacity is called "Use%" and is in a different column.