How to sort lines
Paste lines into the input box or use Upload for a .txt, .csv, .log, .md, or text/plain file. Choose a value under Sort by, set Order, then adjust Blank lines and the comparison options. Sort Lines changes the order of complete lines and leaves the characters inside each line alone. Line ending controls the separators in the output.
- Paste one entry per line into the input box, or choose Upload to load a
.txt,.csv,.log,.md, ortext/plainfile. - Choose Alphabetical, Numeric, Natural (numeric-aware), or Line length under Sort by.
- Choose Ascending or Descending under Order, then set Blank lines, Case-sensitive, and Ignore leading/trailing whitespace.
- Choose Auto (match input), LF (\n), or CRLF (\r\n) under Line ending.
- Copy the result with Copy, or use Download to save
sorted-lines.txt.
Alphabetical, numeric, and natural line sorting
Alphabetical compares each line's text. When Case-sensitive is clear, uppercase and lowercase forms compare together. When Ignore leading/trailing whitespace is selected, those spaces are removed from the comparison key only, so the original line stays intact. Line length measures that same key, which determines if edge spaces count toward length.
Numeric trims the comparison key and reads a numeric prefix with parseFloat. The line 12abc contributes the number 12. In Ascending order, lines without a finite number follow numeric lines. In Descending order, the comparator reverses, so those nonnumeric lines appear before numeric lines. Natural (numeric-aware) compares digit runs as numbers.
Input:
item10
item2
item1
Natural (numeric-aware), Ascending:
item1
item2
item10
What happens to blank lines when you sort?
Blank lines are empty lines or lines made only of whitespace. Sort with other lines sends them through the selected comparison. Keep at top and Keep at bottom remove them from that comparison and place them at the chosen end. Blank lines keep their original order among themselves.
The sort is stable, so lines that compare equally keep their original relative order. The output keeps each line's characters. Line ending controls the separators, and Auto (match input) follows the detected ending. Empty input clears the output and the statistics line.
Examples for sorting lines
- A manifest has identifiers such as
item10,item2, anditem1. Natural (numeric-aware) orders them by the number in each identifier. - A text list has one measurement per line. Numeric orders the lines by their numeric prefixes, then Download saves the result for another text tool.
- Line length groups short or long entries without changing their wording or punctuation.
- A list uses blank lines as separators. Keep at top or Keep at bottom moves those lines while retaining them.
Choose a text organization tool
For a chosen order of complete lines, use Text Organization Tools: Sort, Shuffle & Reverse. Use Shuffle Lines when the order should be random, with its own seed and no-repeat controls. Use Text Reverser when you need to reverse characters or whitespace-delimited chunks inside each line.
Frequently asked questions
How do I sort text lines alphabetically?
Paste the text, choose Alphabetical under Sort by, and choose Ascending or Descending under Order. Case-sensitive and Ignore leading/trailing whitespace change the comparison key, while each line keeps its original characters.
How does a numeric line sorter treat 12abc?
Numeric reads the prefix of 12abc as the number 12. Lines that do not produce a finite number follow numeric lines in Ascending order and precede them in Descending order.
How do I sort lines like item2 and item10?
Choose Natural (numeric-aware) under Sort by. It compares digit runs by number, so item2 comes before item10 in Ascending order.
Can I keep blank lines when I sort lines?
Yes. Choose Sort with other lines, Keep at top, or Keep at bottom under Blank lines. Empty and whitespace-only lines stay in the output.
Does Sort Lines change characters inside a line?
No. Sort Lines reorders complete lines in browser JavaScript, and the page makes no network request with the input. Only the order and, when selected, the separators between lines change.