TOP

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.

No signupRuns locally in your browser

Interactive tool

Line Sorter

Ready

Processing mode

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.

InputOutputMeaning
pear apple bananaapple banana pearDefault example
b aa bBoundary 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

Choose the tool that matches your text or byte workflow.

Advertisement

Sponsored link