(Video materials in preparation)
psort : Partial Sort
Usage : psort ref=<ref> key=<key> <file>
Options : -e
-s<c>
--stable
Version : Tue Jan 9 09:02:34 JST 2024
Edition : 4
Sorts the <key> field for all records that have the same value in
the <ref> field. It sorts in small chunks so it is much faster than
sorting the entire file. <key> and <ref> designates the field
position as fllows:
single field 2 the 2nd field
NF the last field
NF-1 the field just before the last field
contiguous fields 2/4 from the 2nd field to the 4th field
4/2 from the 4th field to the 2nd field
NF-3/NF from NF-3 field to the NF field
combination 2@NF the 2nd field and the NF field
There is no limit on the length of the key field or on the number
of key fields. The key field can also contain multi-byte characters
such as Japanese.
If you specify "r" as sort method after the field position, the
values will be sorted in descending order. If you specify "n" as
sort method after the field position, that field's values will be
sorted as numbers. If you specify "nr" as sort method after the
field, the values will be sorted in descending order as numbers. If
you specify sort method before or after the "/", you must use the
same sort method for both fields.
2n/5n OK
2n/5nr Error
2n/5r Error
When you specify "e" as sort method or specify -e ootion and no
method, characters in the field are replaced as follows and compared
as string:
_ ==> 0x20 (space)
\0 ==> 0x00 (null)
\t ==> 0x09 (tab stop)
\n ==> 0x0a (new line)
\r ==> 0x0d (carrige return)
\_ ==> 0x5f (underscore)
\\ ==> 0x5c (back slash)
If the file name is omitted or if it is specified as "-" then the
command will read from standard input.
The character "_" repalces by space can be chaned by -s<c> option.
$ cat data
A B 1
A A 2
A E 3
A C 4
A D 5
B B 1
B A 2
B E 3
B C 4
B D 5
$ psort ref=1 key=2 data
A A 2
A B 1
A C 4
A D 5
A E 3
B A 2
B B 1
B C 4
B D 5
B E 3