Sort by absolute value

Hi,
I have a file as follows:

  |-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

Please help.

Thanks,
Sudha

$ 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

Perl:

perl -F'\|' -lane'
  push @d, [abs $F[1], $_];
  END {
    print join $/, map $_->[1], sort {
      $a->[0] <=> $b->[0] 
      } @d;  
  }' infile

Get the 2nd column by "cut", then remove the "-" by "sed" and finally "sort -n".

cut -d '|' -f2 | sed 's/[^0-9.]//g' | sort -n

this is the output based on what you've provided:

30.0
50.0
80.0
90.0
100.0

it's not what the OP wanted.

nawk -F'|' '{print ($2>=0)?$2:-$2, $0}' OFS='|' myFile | sort -n -k1,1 | cut -d '|' -f2-

Sorry! You're right. I misunderstood the starter's meaning. :wall:

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