UNIX sort exponents (bc|sort)

UNIX sort exponents (bc|sort)

Post by John Gian » Tue, 14 Nov 2000 04:00:00



John Gianni previously asked:

Quote:>Q: Any idea how to UNIX numerical 'sort' columns containing an exponent?

Given an electrical netlist.txt ASCII text file of the format:
      ...
      current in terminal "/I0/M76/D" is 2.01959e05
      current in terminal "/I0/I31/M0/D" is -5.156252e-05
      current in terminal "/I0/I2/I18/M0/D" is -0.0001061797
      current in terminal "/I0/I2/I18/M0/D" is 0.0001061797
      current in terminal "/I0/I2/M1/D" is -2.110877e06
      current in terminal "/I0/I2/M10/D" is 4.578272e-05
      ...

These methods have kindly been proposed to perform a numerical sort
(smallest to largest) on Sun Solaris 7 UNIX systems:
----------------------------------------------------------------------------
1) sort -r -k 5.3n -k 5.1,5.1n netlist.txt


----------------------------------------------------------------------------
2) awk '{printf "%s %s %s %s %s %10.15f\n",$1,$2,$3,$4,$5,$6}' netlist.txt \
   | sort -n +5


----------------------------------------------------------------------------
3) sortNetlist.pl < netlist.txt
   Where sortNetlist.pl is:
     #!/usr/local/bin/perl

      (split(" ", $a))[5] <=> (split(" ", $b))[5]; } <STDIN>;


      print($line);
      }


----------------------------------------------------------------------------
4) sortNet.pl < netlist.txt | sed -e 's/^ *//g'
  Where sortNet.pl is:
    #!/usr/local/bin/perl

    while (<>) {

        }

    # sort - force whitespace at beginning of each line, and the split
    # on whitespace. Take 6th field and numerically compare

    $a[6] <=>



----------------------------------------------------------------------------

 
 
 

1. UNIX sort exponents (bc|sort)

Q: Any idea how to UNIX 'sort' the fifth column
   (in the file below) such that the exponent is respected?

csh% sort -r -n +5 foo
     Where file foo contains dummy data:
     a b c d f 2e2
     a b c d f 2e-2
     a b c d f 3e2
     a b c d f 3e-2
Does not respect the radix.
Note: Column zero is the first column to the 'sort' command.

Any idea what to feed UNIX sort to make it respect the exponent?
    Mostly, I've tried 'bin/sort' and '/bin/bc' (Sun Solaris 7).

thx,
John

2. Newbie Question: Python and Apache

3. FreeBSD and NUT 0.44.1

4. Crack and NIS+

5. 'at' jobs - getting rid of mail

6. sort sort: 0653-657 A write error occurred while sorting (4.1.3)

7. can unix sort routine sort w/ non ASCII collating sequence?

8. File Sort: How good is Unix sort?

9. sort: write error while sorting: No space left on device??