Sometimes, you have a large file or input stream that is mostly sorted, which you would like to fully sort (e.g. in ascending order).
More formally, suppose, you know that for any record Rn in your stream and any records Rm such that m - n > N, Rn < Rm, where N is constant.
Now, you can sort such a stream, using csv-sort, --sliding-window=<N>:
> ( echo 3; echo 1; echo 2; echo 5; echo 4 ) | csv- sort --sliding-window 3 --fields a 0 1 2 3 > ( echo 4; echo 5; echo 2; echo 1; echo 3 ) | csv- sort --sliding-window 3 --fields a --reverse 3 2 1 0 |
As usual, you can sort by multiple key fields (e.g. csv-sort --sliding-window=10 --fields=a,b,c), sort block by block (e.g. csv-sort --sliding-window=10 --fields=t,block), etc.