Sort Lines

Sort a line list by natural numeric order, alphabetically, character codes or visible length. Optionally trim, ignore case and remove duplicates.

Text is processed locally in your browser and is not uploaded.

Lines sorted
3
Duplicates removed
0
Page guide

How to use this tool

  1. Paste one independent item per line.
  2. Choose the sorting method and direction; optionally trim edges, ignore case, skip empty lines and remove duplicates.
  3. Read the live result and totals. Copy, download or reuse the output; Undo last replacement restores the text before a replacement or clear.

Understanding the output

Natural order recognizes digit sequences; alphabetical order uses English collation. Character-code order compares JavaScript UTF-16 sequences, optionally lowercased. Visible-length order compares grapheme counts and retains input order for equal lengths in either direction. Duplicate removal is optional and runs before sorting, using exact or lowercase keys after any trimming, while keeping the first spelling.

File names with embedded numbers

Natural ascending order changes item 10, item 2, item 1 into item 1, item 2, item 10. Alphabetical ordering may place item 10 before item 2 because it compares text rather than numerical magnitude.

Choose natural sorting for numbered labels

Names such as chapter 2 and chapter 12 contain numbers inside text. Natural ordering is useful for these labels because it keeps their numerical progression readable. It does not turn each line into a mathematical number, and it should not be used to order decimals, negative values, currency, or dates when their numeric meaning matters.

For a dataset that needs numeric analysis, use a spreadsheet or a tool that explicitly parses the relevant number or date field. This sorter treats the full line as the comparison value, including prefixes and surrounding text.

Keep the record boundary clear

A line sorter works well for labels, simple task lists, and one-value records. It is not a CSV row sorter: quoted CSV fields can contain newlines that belong inside one record. Sorting those lines independently would corrupt the structure. Similarly, paragraphs containing several lines should be treated as blocks in a text editor rather than separated into individual entries here.

Method and supported input

Line endings normalize to LF. Optional edge trimming and blank-line removal run before optional exact or lowercase-key deduplication.

Natural and alphabetical modes use English Intl.Collator with numeric comparison only in natural mode. Ignoring case retains accent distinctions. Character-code mode compares UTF-16 keys; length mode uses cached grapheme counts. Stable sorting preserves source order for equal comparison values.

  • One line represents one independent item.
  • English collation is appropriate for the list.

Limitations

  • This is not mathematical sorting of signed or decimal numbers.
  • Collation details can vary slightly with Unicode data in the browser.

Common questions

Can repeated lines be removed while sorting?

Yes. Enable Remove duplicate lines. Matching uses exact text after optional trimming, or lowercase keys when Ignore case is enabled. The first spelling is kept.

Why is the order different from a code-point sort?

Locale collation considers human-language ordering rather than only Unicode character values.

Sources and further reading

Reviewed on