jaapar
November 18, 2015, 1:41am
1
Hi Guys,
I am looking for a way to sort the output below from the "Inuse" count from Highest to Lowest. Is it possible?
Thanks in advance.
user1 0.12 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user2 2.87 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user3 0.17 0.06 0 0.16
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user4 0.12 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user5 0.13 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user6 0.13 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user7 0.11 0.06 0 0.11
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user8 0.21 0.06 0 0.21
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user9 0.75 0.13 0 0.61
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user10 31.7 0.08 0 31.0
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user11 0.12 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
RudiC
November 18, 2015, 3:23am
2
This would work except for the missing separator line of the last record...
paste -sd"\t\t\t\n" file1 | LC_ALL=C sort -k2,2gr | tr '\t' '\n'
user10 31.7 0.08 0 31.0
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user2 2.87 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user9 0.75 0.13 0 0.61
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user8 0.21 0.06 0 0.21
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user3 0.17 0.06 0 0.16
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user5 0.13 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user6 0.13 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user1 0.12 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user11 0.12 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
user4 0.12 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user7 0.11 0.06 0 0.11
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
1 Like
jaapar
November 18, 2015, 4:03am
3
Thanks!!
But i had errors running this one line script. Btw, my server is aix 7.1.
awk 'BEGIN{
FS="[ \t]+"
}
{
if(NR%4==1){
user=$1
users[user]=$0
sort[NR]=$2" "user
}
else{
users[user]=users[user]"\n"$0
}
}
END{
n=asort(sort)
for(i=1;i<=n;i++){
split(sort,items," ")
user = items[2]
print(users[user])
}
}' a
drl
November 19, 2015, 6:49am
5
Hi, jaapar.
Writing i had errors running this one line script is not useful, because we cannot be expected to guess what the error is. Not everyone has access to an AIX system. I guessed that the AIX sort
does not accept everything that GNU sort
accepts. Here is what I found:
#!/usr/bin/env bash
# @(#) s1 Demonstrate sort group of lines.
# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C paste sort tr
FILE=${1-data1}
pl " Input data file $FILE:"
cat $FILE
pl " Results:"
# paste -sd"\t\t\t\n" file1 | LC_ALL=C sort -k2,2gr | tr '\t' '\n'
# paste -sd"\t\t\t\n" data1 | LC_ALL=C sort -k2,2gr | tr '\t' '\n'
paste -sd"\t\t\t\n" data1 | LC_ALL=C sort -k2,2nr | tr '\t' '\n'
exit 0
producing:
$ ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
aix 7.1.0.0
bash GNU bash 4.2.10
paste - ( /usr/bin/paste, Aug 8 2010 )
sort - ( /usr/bin/sort, Sep 5 2012 )
tr - ( /usr/bin/tr, Aug 8 2010 )
-----
Input data file data1:
user1 0.12 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user2 2.87 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user3 0.17 0.06 0 0.16
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user4 0.12 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user5 0.13 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user6 0.13 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user7 0.11 0.06 0 0.11
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user8 0.21 0.06 0 0.21
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user9 0.75 0.13 0 0.61
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user10 31.7 0.08 0 31.0
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user11 0.12 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
-----
Results:
user10 31.7 0.08 0 31.0
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user2 2.87 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user9 0.75 0.13 0 0.61
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user8 0.21 0.06 0 0.21
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user3 0.17 0.06 0 0.16
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user5 0.13 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user6 0.13 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user1 0.12 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user11 0.12 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
user4 0.12 0.06 0 0.12
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
user7 0.11 0.06 0 0.11
User Inuse Pin Pgsp Virtual
Unit: GB
===============================================================================
So a simple change in the sort options seems to work with the code from RudiC.
Help us help yourself -- in the future give us the error message.
Best wishes ... cheers, drl