John Gianni previously asked:
Given an electrical netlist.txt ASCII text file of the format:Quote:>Q: Any idea how to UNIX numerical 'sort' columns containing an exponent?
...
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
while (<>) { # sort - force whitespace at beginning of each line, and the split
(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
}
# on whitespace. Take 6th field and numerically compare
$a[6] <=>
---------------------------------------------------------------------------