Gnu/coreutils/Using-version-sort-in-GNU-coreutils
From Get docs
Next: Origin of version sort and differences from natural sort, Up: Version sort overview [Contents][Index]
30.1.1 Using version sort in GNU coreutils
Two GNU coreutils programs use version sort: ls
and sort
.
To list files in version sort order, use ls
with -v
or --sort=version
options:
default sort: version sort: $ ls -1 $ ls -1 -v a1 a1 a100 a1.4 a1.13 a1.13 a1.4 a1.40 a1.40 a2 a2 a100
To sort text files in version sort order, use sort
with
the -V
option:
$ cat input b3 b11 b1 b20 alphabetical order: version sort order: $ sort input $ sort -V input b1 b1 b11 b3 b20 b11 b3 b20
To sort a specific column in a file use -k/--key
with ‘V
’
ordering option:
$ cat input2 1000 b3 apples 2000 b11 oranges 3000 b1 potatoes 4000 b20 bananas $ sort -k2V,2 input2 3000 b1 potatoes 1000 b3 apples 2000 b11 oranges 4000 b20 bananas