# Sort Lines

Sort lines alphabetically, naturally, by length or at random, with case and blank lines handled. Nothing you paste is uploaded.

Canonical page: https://filetity.com/sort-lines

## Capabilities

- Free: Yes, with no watermark and no page limit.
- Account required: No. There is no account system.
- Processed on device: Yes. The file is read by your browser and never uploaded. There is no server to send it to.
- Formats: Any lines in. Sorted A to Z, Z to A, in natural order, by length, or shuffled.
- Limits: Sorting is by the text of each line. There is no column awareness, so a table of tab separated values sorts by whatever its first column happens to be.
- Mobile: Yes, on any modern mobile browser. Large files are limited by the memory the phone gives the browser.
- Offline: Yes, once the page has loaded. The tool keeps working with no network connection.

## Questions

### Why is file10 before file9 when I sort alphabetically?

Because alphabetical order compares character by character, and the character 1 comes before 9. That is correct and it is almost never what anybody wants for filenames or versions, which is what the natural order option is for: it compares runs of digits as numbers.

### Where do capital letters end up?

Interleaved with lowercase by default, using your locale's own collation, so Apple and apple sit next to each other rather than in two separate blocks. Turn on ignore case if you want them treated as identical for ordering purposes.

### Is the shuffle actually random?

Yes, Fisher-Yates, where every ordering is equally likely. The common one-line version, sorting with a comparator that returns a random number, is noticeably biased because a sort assumes its comparator is consistent and that one is not.

### What happens to blank lines and indentation?

Blank lines are dropped and each line is trimmed by default, because a leading space sorts before every letter and turns a sorted list into a mess. Both are toggles, so you can keep them when the whitespace is meaningful.

### Does sorting by length break ties predictably?

Yes, alphabetically. Without a tie break, two lines of the same length come back in whatever order the engine happened to leave them, which changes between browsers and makes the same input give different output on different machines.

## Related tools

- [Remove Duplicate Lines](https://filetity.com/remove-duplicate-lines): Remove repeated lines, or show only the ones that repeat.
- [Remove Line Breaks](https://filetity.com/remove-line-breaks): Join wrapped lines back into paragraphs, or into one long line.
