Sort Lines Online
This example demonstrates alphabetical line sorting from String Tools, with a pre-filled sample of fruit names. Paste any block of text and sort each line alphabetically in ascending or descending order.
How It Works
The tool splits your input into individual lines, compares each line as a string, and reorders them. Sorting is case-sensitive by default: uppercase letters sort before lowercase (Banana before apple). Switch between ascending (A to Z) and descending (Z to A) order with a single toggle.
Ascending vs Descending
Ascending order puts the first alphabetical line at the top. Descending reverses this. For the sample input, ascending produces:
apple
banana
cherry
date
elderberry
Descending flips it to elderberry first.
Removing Duplicates
Enable the remove-duplicates option to keep only the first occurrence of each line. This is useful when you have repeated entries and want a clean, unique list. The tool preserves the order of first occurrence.
Handling Mixed Content
If your text contains both letters and numbers, remember that lexicographic sorting treats digits as characters. file10.txt sorts before file2.txt because '1' < '2'. For true numeric sorting of filenames, consider padding numbers with zeros first.
How to Use
- Paste your text into the input area (one item per line)
- Select ascending or descending sort order
- Optionally enable remove-duplicates to filter repeated lines
- Copy the sorted output from the result area
Common Questions
Can I sort CSV rows by a specific column?
This tool sorts entire lines. To sort by a specific column, extract that column first (using the find-and-replace tool or a script), sort it, then rejoin with the other columns. Alternatively, paste your CSV into a spreadsheet application which supports column-specific sorting.
Is the sort stable?
Yes. When two lines are equal, they maintain their original relative order. This matters if you have genuinely duplicate lines and want the first occurrence to stay on top.
Does sorting handle Unicode correctly?
The tool uses JavaScript’s default string comparison, which sorts based on Unicode code points. Accented characters and non-Latin scripts sort according to their Unicode position, not necessarily alphabetical order in any particular language.