Story Details

  • The lack of a good command line way to sort IPv6 addresses

    Posted: 2025-05-19 04:04:14

    The blog post laments the absence of a simple, built-in command-line tool in common Unix systems for sorting IPv6 addresses correctly. Standard sorting tools like sort treat IPv6 addresses as strings, leading to incorrect ordering. The author explores several workarounds, including converting addresses to a sortable format using expansion and zero-padding, leveraging specialized tools like ip6calc, or scripting solutions. Ultimately, the post highlights the surprising complexity of this seemingly straightforward task and calls for a more elegant, standardized solution within core Unix utilities.

    Summary of Comments ( 41 )
    https://news.ycombinator.com/item?id=44026414

    HN commenters generally agree that sorting IPv6 addresses from the command line is tricky. Several suggest using sort -k, potentially with some preprocessing via awk or sed to isolate the relevant parts of the address for numerical sorting. Some note the complications introduced by mixed representations (e.g., compressed vs. expanded addresses) and the need to handle various formats like CIDR notation. One commenter highlights the difficulty of sorting IPv6 addresses lexicographically as opposed to numerically. Another commenter suggests a Python solution using the ipaddress module. Several commenters point out that the sort -V (version sort) option likely won't work correctly for IPv6 addresses, reinforcing the original poster's frustration.