- May
- 62
- 1
The TPIPE documentation states, "You can specify multiple filters, which will be processed in the order they appear on the command line." Oh, good: I can specify multiple sort fields. The only thing to look out for is that, since they're executed in order, the most minor sort field should be specified first; and the major sort field last.
So I tried it, and it works -- sort of. Each invocation of the sort does preserve the effect of the preceding sorts -- EXCEPT that the line order is exactly reversed each time.. So if, for example, I want to sort ascending on three different fields, I need to specify DESCENDING for the second sort. (Ascending is okay for the first sort, since its order will be swapped twice by the two subsequent sorts.)
Here's an example. You can experiment with additional passes, swapping the order of the sort fields and flipping the ascending/descending bit.
Or am I perhaps making a grossly incorrect assumption that the sort algorithm is actually preserving anything from previous passes, and it just happens that all the cases I've tried so far seem to conform to the pattern I described? (My testing has been limited to files of under 1000 lines.)
So I tried it, and it works -- sort of. Each invocation of the sort does preserve the effect of the preceding sorts -- EXCEPT that the line order is exactly reversed each time.. So if, for example, I want to sort ascending on three different fields, I need to specify DESCENDING for the second sort. (Ascending is okay for the first sort, since its order will be swapped twice by the two subsequent sorts.)
Here's an example. You can experiment with additional passes, swapping the order of the sort fields and flipping the ascending/descending bit.
Code:
[D:\tmp]type foo.txt
2bX
1bX
2aX
1aX
2bX
1bX
2aX
1aX
2bO
1bO
2aO
1aO
2bO
1bO
2aO
1aO
[D:\tmp]tpipe /input=foo.txt /sort=0,0,0,1,1 /sort=0,1,0,2,1 /sort=0,0,0,3,1
Or am I perhaps making a grossly incorrect assumption that the sort algorithm is actually preserving anything from previous passes, and it just happens that all the cases I've tried so far seem to conform to the pattern I described? (My testing has been limited to files of under 1000 lines.)