Code Beautifier

Sort & Remove Duplicate Lines

Sort lines naturally or alphabetically, remove duplicates keeping the first or last, reverse, or shuffle, with line endings preserved.

Draft saved locally.

Local workspace

Named projects in IndexedDB · Local only — never synced to our servers. Worksp

Open manager

Batch workspace

Format multiple files locally in one run.

Operation:
Order:
text
Formatted Outputtext

Sorting and deduping lines is the kind of task that gets done with a half-remembered sort | uniq pipeline, which silently changes the parts you cared about: uniq only removes adjacent duplicates, and a plain sort puts file10 before file2. This tool sorts naturally by default, removes duplicates anywhere in the list while letting you keep the first or last copy, and leaves CRLF endings and a trailing newline as it found them. Trimming and case sensitivity are separate switches, so you can decide whether lines that differ only in spacing or capitalization count as the same.

Common errors and fixes

The output lost my blank lines

Remove empty lines is on by default. Turn it off to keep them, though sorting will group them together.

Duplicates weren't removed

The lines differ invisibly, usually by trailing whitespace or capitalization. Turn on Trim whitespace, and leave Case sensitive off.

Line endings changed after sorting

The output uses the endings the input had, and a file with mixed endings is normalized to CRLF if any CRLF is present. Normalize the file first if that matters.

Version numbers sort in the wrong order

Alphabetical order puts 1.10 before 1.9. Choose natural order, which compares the numbers by value.

Options

OptionDescription
OperationSort can also drop duplicates. Remove duplicates on its own keeps the original order.
OrderNatural order compares embedded numbers by value, which is what you want for filenames and versions.
DescendingReverses the sort order.
Also remove duplicatesDrops repeated lines while sorting.
KeepWhich copy of a repeated line to keep. Last is useful when later lines override earlier ones.
Case sensitiveOff, Apple and apple count as the same line and sort together.
Trim whitespaceRemoves leading and trailing spaces before comparing, so lines that differ only in spacing count as duplicates.
Remove empty linesTurn off to keep blank lines in the output.

FAQ

What does natural order do differently?

It compares numbers inside the text by value, so file2 comes before file10. Alphabetical order compares character by character, which puts file10 first because 1 sorts before 2.

Should duplicates keep the first or the last copy?

Keep first preserves the earliest position, which suits lists you're deduping. Keep last suits config files and environment variables, where a later line overrides an earlier one.

Are blank lines and indentation preserved?

Blank lines are dropped by default and you can keep them with an option. Indentation is kept unless you turn on trimming, which removes leading and trailing spaces before comparing.

Is the comparison case sensitive?

Not by default, so Apple and apple are treated as the same line. Turn on Case sensitive for exact matching, which also separates them when sorting.

How random is the shuffle?

It uses a Fisher-Yates shuffle with the browser's cryptographic random source and rejection sampling, so every ordering is equally likely rather than merely scrambled.