The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
not getting the output properly pmrajesh21 SUN Solaris 0 04-16-2008 10:43 AM
Output in my shell isn't showing properly. satyakide Shell Programming and Scripting 7 04-01-2008 10:05 AM
sort output funksen Shell Programming and Scripting 9 01-14-2008 04:40 AM
how to sort and arrange an output llsmr777 UNIX for Dummies Questions & Answers 10 11-12-2007 09:39 PM
How to output the results of the AT command - properly! SpanishPassion UNIX for Dummies Questions & Answers 4 12-04-2005 10:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-04-2008
shew01 shew01 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 41
Korn: How to zero fill df output so it will sort properly

I'm looking for a way in Korn shell to zero fill (or space fill) the output from df so that it will sort properly.

"Raw" output from df -k:

Code:
df -k

Filesystem            kbytes    used   avail capacity  Mounted on
/dev/vx/dsk/rootvol  4131866 3593302  497246    88%    /
/proc                      0       0       0     0%    /proc
fd                         0       0       0     0%    /dev/fd
mnttab                     0       0       0     0%    /etc/mnttab
swap                 19891520     144 19891376     1%    /var/run
swap                 19913552   22176 19891376     1%    /tmp
/dev/vx/dsk/u01      112302757 30833295 80346435    28%    /u01
/dev/vx/dsk/node@1     96975    4977   82301     6%    /global/.devices/node@1
/dev/vx/dsk/node@2     96975    4988   82290     6%    /global/.devices/node@2
/dev/vx/dsk/stkdg/s03
                     1047527424 60483821 925353439     7%    /s03
/dev/vx/dsk/stkdg/s02
                     1048576000 266754165 732957997    27%    /s02
/dev/vx/dsk/sandg/s01
                     355923968 322572197 31422792    92%    /global/s01
Sorted df output (which incorrectly sorts 28% and 27% after 7%):

Code:
df -k | grep / | awk '{ print $5}' | sort -r

92%
88%
7%
6%
6%
28%
27%
1%
1%
0%
0%
0%
I would like the output to display in the following format:

Code:
92%
88%
28%
27%
 7%
 6%
 6%
 1%
 1%
 0%
 0%
 0%
Any ideas?
  #2 (permalink)  
Old 06-04-2008
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
The output you are getting is not "incorrect". It is actually correct with the flags you are giving sort.
You have to tell sort that you are sorting numbers and not text.
Code:
:> df -k | grep / | awk '{print $5}' | sort -gr
100%
7%
2%
0%
0%
A quick look at the man pages would've given you the answer.
  #3 (permalink)  
Old 06-04-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
Code:
df -k | awk '/[/]/ { print $5}' | sort -rn
  #4 (permalink)  
Old 06-04-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,793
Or:
if perl is acceptable:

Code:
df -k | 
  perl -ane'
    /%/ and push @x,$F[4];
    print join "\n" , reverse sort { $a <=> $b } @x 
if eof'
Otherwise:

Code:
df -k |awk '1<NR&&NF>1{print $5}'|sort -nr
  #5 (permalink)  
Old 06-04-2008
shew01 shew01 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 41
System Shock,

>>A quick look at the man pages would've given you the answer.

I don't think so:

Code:
df -k | grep / | awk '{print $5}' | sort -gr
sort: illegal option -- g
usage: sort [-cmu] [-o output] [-T directory] [-S mem] [-z recsz]
        [-dfiMnr] [-b] [-t char] [-k keydef] [+pos1 [-pos2]] files...
  #6 (permalink)  
Old 06-04-2008
shew01 shew01 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 41
vgersh99,

Quote:
Originally Posted by vgersh99 View Post
Code:
df -k | awk '/[/]/ { print $5}' | sort -rn
Cool! This seems to work. Thanks for the help.
  #7 (permalink)  
Old 06-04-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,793
And another one:

Code:
df -k | 
  while read fs kb us av ca mo; do 
    case $ca in 
      *[0-9]% ) printf "%s\n" "$ca";;
    esac
done | sort -rn
You should use df -P on Linux.
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 11:07 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0