Skip to content
PithLab

↑↓ to move · Enter to open · Esc to close

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"}'

Fields and responseOpenAPI documentGet an API key

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

  1. Paste your list into the input box, one item per line.
  2. Pick a sort order: A–Z, natural, by length, or shuffle.
  3. Tick Reverse order for Z–A or longest-first, and Remove duplicates or Remove blank lines if needed.
  4. The sorted result updates as you type. In shuffle mode, press Shuffle to get a new random order.
  5. Copy the result or download it as a text file.

Examples

Alphabetical, ignoring case

Input

banana
Apple
cherry
apricot

Output

Apple
apricot
banana
cherry
Natural order for numbered items

Input

file10.txt
file2.txt
file1.txt

Output

file1.txt
file2.txt
file10.txt
Shortest line first

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.