Skip to content

sort: implement -V version sort #907

@chaliy

Description

@chaliy

Problem

sort -V (version/natural sort) is parsed as a flag in sortuniq.rs but not implemented. Version sort is commonly used for sorting filenames, package versions, and semantic version strings.

Expected behavior

printf '1.10\n1.2\n1.1\n' | sort -V
# 1.1
# 1.2
# 1.10

Segments of digits are compared numerically, non-digit segments are compared lexically. This handles cases like file-1.2.txt vs file-1.10.txt correctly.

Current code

sortuniq.rs:149'V' flag is matched but no version comparison logic exists. Falls through to default lexical sort.

Suggested approach

uutils/coreutils (MIT) has a version comparison implementation. The algorithm is non-trivial (splitting strings into numeric/non-numeric chunks, comparing each chunk appropriately). Consider borrowing their version_cmp logic — it's pure string comparison with no FS dependency.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions