Sort Lines

Sort each line of text from first to last, or the other way. The order follows the text locale you select.

Use this tool

Result

The result appears in this panel after you run the tool.

About this tool

The page splits lines the same way as Remove Duplicate Lines: \r\n and \r become \n, and a trailing newline is an empty last line. That empty line sorts with the others, so a trailing newline can move to the top in ascending order. Omit the final newline if you do not want a blank row.

Ordering uses Intl.Collator for the selected text locale. Swedish sorts ö after z. Turkish sorts ı before i. It is a textual sort: 10 comes before 2. Lines that compare as equal keep their original order in both ascending and descending sorts.

The text locale starts as your browser’s preferred language when that language is one this page supports, and English otherwise. Choosing a locale saves only that locale id in this browser under utilchain-text-locale. The lines themselves are not saved there. Case conversion uses the same choice. Base64 and JSON stay byte-oriented and do not use this order.

You can remove duplicate lines before or after sorting. Following that suggestion passes the current text in this browser only. A refresh can discard it.

How to use it

  1. Paste the rows you want to sort.
  2. Choose ascending or descending, then sort.
  3. Download the text or continue with another tool. The handoff stays in this browser.

Limitations

Whole rows, in locale order

What is being ordered

Each line is one sort key. The locale’s collation decides whether “a” and “A” sit together and whether accented letters share a base letter. Ascending and descending use that same collation in opposite directions. The page does not look inside the line for a column, a comma, or a date. “2024-01-09, zebra” and “2024-12-01, apple” sort by the whole string, which often happens to follow the date only because the date is at the start and is zero-padded.

Numbers in a line sort as text

“10” comes before “2” in a text sort because the character “1” comes before “2”. That surprises people who wanted numeric order. This page will not parse a leading integer out of the row. If the rows are bare numbers, use the number sorter, which compares magnitudes. If the rows are “item 10” and “item 2”, neither page will do a natural sort of the embedded numeral unless you isolate that numeral first.

Blank lines and stability of duplicates

A blank line is a key. It sorts to one end, depending on direction, rather than disappearing. Duplicate lines stay duplicate. This page does not unique them. Remove duplicate lines if you wanted one copy. The first physical row is not specially protected during a sort, because order is the point. If you needed the original order of first occurrences, sort is the wrong tool. Locale changes can reorder the same file, so write down which locale you used when the order is part of a deliverable.

Dates and codes only sort when you shaped them

ISO dates with four-digit years and zero-padded months sort chronologically as text because the most significant part is on the left. “9/1/2024” and “10/1/2024” do not, because “1” and “9” decide first. Rewrite the key before you sort, or sort a column in a spreadsheet. This page will not guess which field inside the row was the key.

Privacy

Your text is processed in your browser and is not uploaded to UtilChain. The lines are not included in analytics.