manpagez: man pages & more
info coreutils
Home | html | info | man

File: coreutils.info,  Node: The tilde ~,  Next: Version sort ignores locale,  Prev: Punctuation vs letters,  Up: Version sort implementation

30.2.5 The tilde ‘~’
--------------------

Rule 2.B.b says the tilde ‘~’ (ASCII 126) sorts before other bytes, and
before an empty string.

     $ cat input7
     1
     1%
     1.2
     1~
     ~
     $ sort -V input7
     ~
     1~
     1
     1%
     1.2

   The sorting algorithm starts by breaking down the string into
non-digit (rule 2) and digit parts (rule 3).

   In the above input file, only the last line in the input file starts
with a non-digit (‘~’).  This is the first part.  All other lines in the
input file start with a digit – their first non-digit part is empty.

   Based on rule 2.B.b, tilde ‘~’ sorts before other bytes and before
the empty string – hence it comes before all other strings, and is
listed first in the sorted output.

   The remaining lines (‘1’, ‘1%’, ‘1.2’, ‘1~’) follow similar logic:
The digit part is extracted (1 for all strings) and compares equal.  The
following extracted parts for the remaining input lines are: empty part,
‘%’, ‘.’, ‘~’.

   Tilde sorts before all others, hence the line ‘1~’ appears next.

   The remaining lines (‘1’, ‘1%’, ‘1.2’) are sorted based on previously
explained rules.

© manpagez.com 2000-2025
Individual documents may contain additional copyright information.