Name: ntropia Date: April 19, 2006 at 04:33:04 Pacific Subject: Numerical sort with sort OS: Linux CPU/Ram: Itanium 1Gb Model/Manufacturer: Intel
Comment:
I'm trying to sort a file containing fields. The two I use for sort contain numerical values, but they includes "+" or "-" signes. Even using the -n flag of sort, final result is uncorrect, because it doesn't care about the signe. There is a way to make that two-field sort, even not using the sort command? (I'm not expert of perl nor awk) Thanks!
My idea is that sort uses the 6th field to sort first, then, values showing the same value for that field will be sorted further using the 5th field. It's this correct? Thanks,
I was imprecise when I sayd "first field": I meant the first field used (the 6th, or the 1.44,1.48 as seen by sort). I would like sort will order lines in a way that lines ... 7 17 | 0.14 | 32 | 1.14 | 3 |### 8 11 | -2.03 | 24 | -0.05 | 3 |### ... will be ranked as: 8 11 | -2.03 | 24 | -0.05 | 3 |### 7 17 | 0.14 | 32 | 1.14 | 3 |### accordingly first to the 6th field then to the 5th field. I hope that's more clear, now... :-P
Well, it's not exactly what I'm looking for, but probably it's my fault because it's a bit complicated for me too. To be honest, the first field was added by me, accordingly to a trick that (maybe) your self suggest in a prevoius post (a piping to a "| cat -n" after a first sort). A simpler example, four fake lines: INPUT: X | XX | XX | XX | -4.9 | 4 X | XX | XX | XX | 1.9 | 4 X | XX | XX | XX | -8.9 | 10 X | XX | XX | XX | -3.9 | 20
There are two criteria I would use when sorting: 1. the 6th field, decreasing (higher values=better) 2. the 5th field, increasing (lower values=better)
That's the *real* problem.
It should be damn'easy, using the fields 1st and 6st:
FINAL OUTPUT (DESIRED) X | XX | XX | XX | -3.9 | 20 X | XX | XX | XX | -8.9 | 10 X | XX | XX | XX | -4.9 | 4 X | XX | XX | XX | 1.9 | 4
...but how to manage the two sort orders (decreasing and increasing) in the same time?
Anyway, my best thanks for your patience up to now.
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE