Results 1 to 5 of 5
I am using bash and need to sort a bunch of numbers that look like the following example:
Code:
9.1
9.2
...
9.N
10.1
10.2
...
10.N
I am having ...
- 09-24-2007 #1
Bash: sorting by two fields
I am using bash and need to sort a bunch of numbers that look like the following example:
I am having trouble because the sort command either sorts by one field or the other, so if I just | sort -n I end up withCode:9.1 9.2 ... 9.N 10.1 10.2 ... 10.N
Does anyone have a cunning way of sorting by field one and then subsorting by field 2 without losing the order of the first field? If I sort by field 2 then of course the 9 and 10 at the beginning would could out of order.Code:9.1 9.20 9.21 ... 9.2 9.30 9.31 ... 9.3 ... 10.1 10.20 10.21 ... 10.2
- 09-24-2007 #2
I don't understand the problem. What is your desired output?
- 09-24-2007 #3
I wanted to make .5 come before .40 because I am sorting IP addresses.
It is ok, there is a little used switch -k which did what I wanted.
- 09-24-2007 #4
I think the search key switch is one of the most used, besides -n. At least, in my Linux scripts it is. Problem is, -k isn't portable. Well, it's only a problem if you intend on running the script on anything besides Linux that isn't using GNU sort.
- 09-24-2007 #5
Actually, scratch that, I think it's the modifiers that may behave differently, that are sometimes used in conjunction with -k.


Reply With Quote