Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Natural Sorting utility

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .gitignore
Octocat-spinner-32 AUTHORS
Octocat-spinner-32 COPYING
Octocat-spinner-32 HISTORY
Octocat-spinner-32 Makefile.am
Octocat-spinner-32 README.md
Octocat-spinner-32 autogen.sh
Octocat-spinner-32 configure.ac
Octocat-spinner-32 main.c
Octocat-spinner-32 natsort.pod
Octocat-spinner-32 sort.c
Octocat-spinner-32 sort.h
README.md

Natural Sorting utility

natsort is a small tool to sort a list of lines, using natural sort order. It reads lines to sort from its standard input and writes them sorted on standard output.

What is natural order?

Most sorting utility perform a simple ASCII comparison, with works as computers might expect things, but not so much our human selves; Because when numbers are involed, e.g. with "test15" and "test2" we usually want to see "test2" before "test15" even though, taken character by character, 1 does come before 2.

There's been plenty of talk about this, the point being: natural order is what people will mostly (if not always) expect, but not what they always get.

natsort will perform natural sort order, and in case two numbers evaluate to the same value but aren't the same (i.e. one has (more) leading zeros, e.g. 02 vs 002) the one with less leading zeros will come first.

Unfortunately things aren't so simple as to simple treat numbers differently, because people might expect ordering based on their locale, so that characters with accents are placed alongside their accent-free counterparts and such.

This will not happen with natsort, because its comparison isn't locale based. It performs simple character comparisons, but with support for natural order and a few more options (e.g. case sensitivity).

Want to know more?

natsort is a simple example of an implementation of natural sort order. For more information :

Plus, natsort comes with a man page.

Something went wrong with that request. Please try again.