|-30.0|Appls. executing in db manager currently = 2
|-80.0|Locks held currently = 1
| 90.0|High water mark (bytes) = 65536
|-50.0|Configured size (bytes) = 16777216
|-100.0|Current size (bytes) = 131072
I want to sort on the absolute value of the second column with '|' as delimeter. sort -n sorts the field numerically but cannot sort by its absolute value ignoring the signs.
I would like to get an output as follows:
|-30.0|Appls. executing in db manager currently = 2
|-50.0|Configured size (bytes) = 16777216
|-80.0|Locks held currently = 1
| 90.0|High water mark (bytes) = 65536
|-100.0|Current size (bytes) = 131072
$ sed 's/| \([^-]*\)|/|-\1-|/' file|sort -t'|' -k2,3 -nr|sed 's/|-\(.*\)-|/| \1|/'
|-30.0|Appls. executing in db manager currently = 2
|-50.0|Configured size (bytes) = 16777216
|-80.0|Locks held currently = 1
| 90.0|High water mark (bytes) = 65536
|-100.0|Current size (bytes) = 131072
With gawk (WHINY_USERS for gawk version 3.x, PROCINFO for gawk version 4):
WHINY_USERS=1 gawk -F\| '{
x = sprintf("%6.1f", $2 > 0? $2 : -$2)
if (x in a) a[x] = a[x] "\n" $0
else a[x] = $0
}
END {
PROCINFO["sorted_in"] = "@ind_num_asc"
for (i in a) print a
}' infile