Sort Lines Alphabetically, Naturally or by Length
Sort, reverse or shuffle lines, with optional de-duplication.
Use via API
Sort lines alphabetically, naturally (1, 2, 10), by length, or shuffle them, with options to reverse, de-duplicate and drop blank lines. Send JSON, get JSON back.
POST https://pithlab.com/api/v1/tools/sort-lines
curl https://pithlab.com/api/v1/tools/sort-lines \
-H "Authorization: Bearer $PITHLAB_KEY" \
-H "Content-Type: application/json" \
-d '{"input":"file10.txt\nfile2.txt\nfile1.txt","mode":"natural"}'About the Sort Lines
Sort lines of text A–Z or Z–A, in natural number order, or by length, or shuffle them randomly. Optionally remove duplicates and blank lines as you sort.
How to use the Sort Lines
- Paste your list into the input box, one item per line.
- Pick a sort order: A–Z, natural, by length, or shuffle.
- Tick Reverse order for Z–A or longest-first, and Remove duplicates or Remove blank lines if needed.
- The sorted result updates as you type. In shuffle mode, press Shuffle to get a new random order.
- Copy the result or download it as a text file.
Examples
Input
banana Apple cherry apricot
Output
Apple apricot banana cherry
Input
file10.txt file2.txt file1.txt
Output
file1.txt file2.txt file10.txt
Input
elephant cat mouse
Output
cat mouse elephant
Frequently asked questions
What is natural sorting?
Natural sorting compares runs of digits as numbers, so item2 comes before item10. Plain alphabetical sorting compares character by character and would put item10 first.
How are accented letters and other languages sorted?
Sorting uses your browser's Unicode collation (Intl.Collator) for your language, so é sorts next to e rather than after z, and lines in other alphabets sort correctly for your locale.
How random is the shuffle?
Shuffling uses the Fisher–Yates algorithm with your browser's cryptographically secure random number generator and rejection sampling, so every ordering is equally likely.
What happens to lines that compare equal?
The sort is stable: lines that are equal for the chosen order, such as Apple and apple when case is ignored, stay in their original relative order.