UNIX sort exponents (bc|sort) 
Author Message
 UNIX sort exponents (bc|sort)

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



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



Fri, 02 May 2003 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Sort (List sorts...)

2. Binary Sort/Merge Sort in awk

3. ANN: New release of S.C.A. Micro Templates (Browse Header Sort and Reverse Sort Template)

4. Sort of Sorts

5. All Sorts of Sorts

6. All Sorts of Sorts

7. All Sorts of Sorts

8. All Sorts of Sorts

9. Straight Insertion Sort and Binary Insertion Sort

10. Bubble sort/Selection sort help neded.

11. Sorting a file w/o SORT verb

12. Sorting Tables with sort-merge ??

 

 
Powered by phpBB® Forum Software