Free exact browser converter
Line Sorter
Sort text lines in ascending, descending or natural numeric order. Keep duplicate lines and preserve one final newline when present.
Interactive tool
Line Sorter
Ready
Choose a clear output representation.
Detailed conversion guide
How Line Sorter Works
Ascending and descending modes compare strings using JavaScript lexical order. Uppercase and lowercase can sort differently. These modes do not guess numbers inside a line.
Natural mode uses an English numeric collator, so file2 comes before file10. It ignores case for comparison and retains the order of ties.
| Input | Output | Meaning |
|---|---|---|
pear
apple
banana | apple
banana
pear | Default example |
b
a | a
b | Boundary example |
JavaScript Example
Runnable example for the default sample. The tool also validates its full input contract.
const sorted=input.split("\n").sort((a,b)=>a<b?-1:a>b?1:0).join("\n");Formats, Boundaries and Limitations
Blank lines are real records and sort with the others. Duplicate lines remain. A terminal newline is preserved separately rather than treated as an extra record.
Line endings are normalized to LF. Natural collation follows the browser’s internationalization data and is not a universal language-independent sort.
Related converters
More Text and Encoding Tools
Choose the tool that matches your text or byte workflow.