Sort list by last character

Sort a list by the last character of each item. Items are grouped by their trailing character (`apple`/`banana` both end in "a" → group together; then `dog`; then `cat`/`elephant` both end in "t" → grouped; then `fox`). Within each group, items come out in alphabetical order. Handy for rhyme order, file-extension grouping, or any job where the tail of the line is what matters.

Input
Ready
Output
Live

Group by trailing character, alphabetical tiebreak

The comparator reads the final character of each line (`[...s].at(-1)` - Unicode-aware, so surrogate-pair emoji and supplementary-plane characters stay intact instead of being split mid-code-point). Items are grouped by that character, and items whose last character is equal fall back to full-line alphabetical order for a stable, human-readable result.

Example: `apple / dog / banana / cat / fox / elephant` becomes `banana` (a), `apple` (e), `dog` (g), `cat` (t), `elephant` (t), `fox` (x). The two "t" items keep alpha order among themselves via the tiebreak.

Mode also exposes whole-line alphabetical, numeric, and by-length so the same tool can handle ordinary sort jobs too. Case sensitive off (default) treats `Apple` and `apple` as equal on the tiebreak; turn on to distinguish them.

How to use sort list by last character

  1. 1Paste your list into the input panel
  2. 2Default Mode is "By last character"; leave it to sort by trailing character
  3. 3Ascending (default) groups a-z by last char; Descending reverses that ordering
  4. 4Within a group of same-last-char items, the alphabetical tiebreak orders them consistently
  5. 5Switch Mode to Alphabetical / Numeric / By length for other sort axes

Keyboard shortcuts

Drive ListShift without touching the mouse.

Shortcut Action
Ctrl ZUndo last input change
Ctrl Shift ZRedo
Ctrl Shift EnterToggle fullscreen focus on the editor
EscExit fullscreen
Ctrl KOpen the command palette to jump to any tool
Ctrl SSave current pipeline draft Plus
Ctrl PRun a saved pipeline Plus

What this tool actually does

Native last-character sort with alphabetical tiebreak. Unicode-aware.

Groups by trailing character

The comparator reads `[...line].at(-1)` from each item - the final Unicode code point. Items with the same last character come out next to each other; the group order is alphabetical on that character (a before b before c, etc.).

Alphabetical tiebreak within a group

Two items sharing a last character fall back to full-line `localeCompare` for their relative order. `cat` and `elephant` both end in "t"; in the output `cat` comes before `elephant` because c < e. Keeps output deterministic across runs.

Unicode-aware last-char extraction

Uses the spread operator (`[...line]`) which iterates by code point, not by UTF-16 code unit. Items ending in emoji or supplementary-plane characters stay intact instead of being split mid-surrogate-pair.

Four modes via the shared sort op

By last character (default), Alphabetical (whole line), Numeric, or By length. Pick the mode that matches your sort key; all four share the same Order + Case-sensitive controls.

Case sensitive toggle

Off (default) groups `cat` and `CAT` together (both end in "t" regardless of case). On distinguishes `T` from `t` in the grouping. Also affects the tiebreak.

Worked example

Default By-last-character mode. Items grouped by trailing letter (a → e → g → t → x); ties on "t" broken alphabetically so `cat` comes before `elephant`.

Input
apple
dog
banana
cat
fox
elephant
Output
banana
apple
dog
cat
elephant
fox

Settings reference

How each option shapes the output using the sample above.

Setting What it does Effect on the sample
Mode: By last character (default), Order: A→Z Groups items by trailing character; alphabetical tiebreak `banana` (a) / `apple` (e) / `dog` (g) / `cat` (t) / `elephant` (t) / `fox` (x)
Mode: By last character, Order: Z→A Reverses the grouping order (x before t before g...); tiebreak still alphabetical within a group `fox` / `cat` / `elephant` / `dog` / `apple` / `banana`
Mode: Alphabetical (whole line) Standard full-line alpha sort (same op as Sort a list) `apple` / `banana` / `cat` / `dog` / `elephant` / `fox`
Mode: By length Sorts by character count with alphabetical tiebreak `dog` (3) / `cat` (3) / `fox` (3) / `apple` (5) / `banana` (6) / `elephant` (8)
Case sensitive: on Distinguishes `T` from `t` in grouping and tiebreak No visible change on the sample - all items lowercase

FAQ

How does it order items that end in the same character?
Alphabetical on the full line. `cat` and `elephant` both end in "t"; `cat` comes first because c < e. The tiebreak is stable across runs — same input always produces the same output.
What happens with emoji or non-ASCII trailing characters?
Handled correctly. The last-character extraction uses `[...line].at(-1)` which iterates by Unicode code point, so surrogate-pair emoji (🥇, 😀) and supplementary-plane characters stay intact instead of being split mid-codepoint. An item ending in 🔥 groups with other items ending in 🔥.
How do I group files by extension?
If the extensions all have the same length (all `.txt`, all `.jpg`), this tool works directly - the last character ("t", "g", etc.) groups them. For multi-character extensions where last-char alone is ambiguous, use Replace with regex `^(.+?)(\.\w+)$` → `$2\t$1` to put the extension first, then run standard alphabetical sort.
How is this different from Sort a list?
Sort a list compares full lines starting from the first character. This tool compares the LAST character first, with full-line alphabetical as the tiebreak. Two items starting with different letters but ending with the same letter group together here, but not on Sort a list.
Does empty line go first or last?
First. An empty line has no last character, which `localeCompare` treats as coming before any real character - so empty lines sort to the top regardless of order direction on the rest of the list.