On 24/10/2011 21:35, John W. Krahn wrote: > > You forgot the part where the OP wants to sort the output. :-)
I thought I didn't have enough information to know how the OP wanted the report sorted, but I see from the attacked shell script that the original lines from the df output are sorted before reformatting. To achieve that the complete df listing must be in memory, so it is simpler to use backticks rather than opening a pipe. The fix below replaces the original code from # Open a pipe from the df command to the end of the while loop. The rest of the program stays the same. Cheers, Rob my @data = `df -k`; # Drop the header line and sort the data lines # shift @data; @data = sort @data; # Parse each data record into a hash. # Convert the KBytes field to new MBytes and GBytes fields. # Do the same in-place for Used and Avail. # And replace the data line with a referece to the new hash # foreach (@data) { my %rec; @rec{qw/Filesystem KBytes Used Avail Capacity Mount/} = split; $rec{MBytes} = kb_to_mb $rec{KBytes}; $rec{GBytes} = kb_to_gb $rec{KBytes}; $rec{$_} = kb_to_mb $rec{$_} for qw/Used Avail/; $_ = \%rec; } **OUTPUT** Filesystem MBytes Used Avail Capacity Mount -------------------------------------- --------- --------- -------- -------- ----------------- /dev/md/dsk/d1 3027-MB 2424-MB 542-MB 82% / /dev/md/dsk/d3 3027-MB 1558-MB 1408-MB 53% /var /dev/md/dsk/d4 4886-MB 4229-MB 608-MB 88% /opt /proc 0-MB 0-MB 0-MB 0% /proc dev0ns951:/vol/vol_admin/admin 38810-MB 32189-MB 6621-MB 83% /nas_mnt/admin dev0ns951:/vol/vol_admin/admin/cpadocs 38810-MB 32189-MB 6621-MB 83% /opt/info dev0ns951:/vol/vol_admin/common 314368-MB 260633-MB 53735-MB 83% /nas_mnt/common dev0ns951:/vol/vol_admin/docs 8270-MB 7076-MB 1194-MB 86% /nas_mnt/docs dev0ns951:/vol/vol_admin/prodhome 32870-MB 25964-MB 6906-MB 79% /home/users dev0ns951:/vol/vol_admin/prodhome 32870-MB 25964-MB 6906-MB 79% /nas_mnt/prodhome dev0ns951:/vol/vol_admin/saphome 90-MB 37-MB 53-MB 42% /nas_mnt/saphome fd 0-MB 0-MB 0-MB 0% /dev/fd mnttab 0-MB 0-MB 0-MB 0% /etc/mnttab swap 8460-MB 0-MB 8460-MB 1% /var/run swap 8513-MB 54-MB 8460-MB 1% /tmp -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/