Sort Lines in the Browser: Numbers, Case and the Whitespace That Decides the Order

I work on OnePassApps. We build browser studios that do their work in the tab instead of uploading your files, and Text Studio is the one for plain text: eight tools on one tab bar - Clean, Case, Duplicate lines, Sort lines, Find & replace, Diff, Markdown and Base64. The Sort lines tab is the one that looks trivial until you feed it a list that is not a plain list of names. Version strings, IDs typed as text, a column of numbers - each of those has a different idea of what "sorted" means. So this is about the ordering rules rather than the button: what the three options do, and what the tool does with spaces, blank lines and duplicates. The page describes itself in one line: "Count, clean, compare and convert text locally. Your content stays in this browser tab." What the tab gives you One panel, three steps. 01 Input text - a box with a live counter (2,000,000 characters on this tab) and a live stats row: Words, Characters, Sentences, Lines and UTF-8 bytes. 02 Options -

Sort Lines in the Browser: Numbers, Case and the Whitespace That Decides the Order

I work on OnePassApps. We build browser studios that do their work in the tab instead of uploading your files, and Text Studio is the one for plain text: eight tools on one tab bar - Clean, Case, Duplicate lines, Sort lines, Find & replace, Diff, Markdown and Base64.

The Sort lines tab is the one that looks trivial until you feed it a list that is not a plain list of names. Version strings, IDs typed as text, a column of numbers - each of those has a different idea of what "sorted" means. So this is about the ordering rules rather than the button: what the three options do, and what the tool does with spaces, blank lines and duplicates.

The page describes itself in one line: "Count, clean, compare and convert text locally. Your content stays in this browser tab."

What the tab gives you

One panel, three steps. 01 Input text - a box with a live counter (2,000,000 characters on this tab) and a live stats row: Words, Characters, Sentences, Lines and UTF-8 bytes. 02 Options - three controls: Sort order (A to Z or Z to A), Case-sensitive and Natural number order. 03 Result - "Sorted lines shows on the stage, ready to copy, download or use as the new input."

The action button reads "Sort lines" and becomes "Sort again" once a run has happened. The result panel then reports the size of what it produced and how long it took ("Sorted in 0.2 s"), and offers Use as input, Download .txt and Copy. The stage footer reads "Text transformed locally." and the panel says "Nothing leaves this tab."

You can drop a file in instead of pasting: the drop area takes ".txt, .md, .csv and other text up to 8 MiB", and the tab says "Processing stays in this browser."

Run 1 - what the defaults do with numbers

Input (6 lines, 33 characters - the stats row read Words 7, Characters 33, Sentences 0, Lines 6, UTF-8 bytes 33):

banana
Apple
10
9
cherry
2 apples

Options left where they ship: Sort order A to Z, Case-sensitive off, Natural number order on. Result:

2 apples
9
10
Apple
banana
cherry

Two things happened. The numbers came first and in numeric order - 9 before 10, not "10" before "9" the way a plain text sort does it. And "2 apples", which starts with a digit, was treated as a number and sorted into that group: 2, then 9, then 10. Everything that does not start with a digit came after, alphabetically.

Run 2 - the same input with Natural number order switched off

10
2 apples
9
Apple
banana
cherry

That is plain lexicographic order: "10" first because the character "1" comes before "2", and "2 apples" before "9". If your list is numbers stored as text, this is the difference between a useful order and a broken one. Natural number order is on by default, which is the right default for a list of IDs, and the one to turn off for version strings.

Run 3 - Case-sensitive, and what the toggle actually changes

The checkbox sits under Sort order and ships off. Here is the same input sorted twice.

Input:

Zebra
apple
Apple

Case-sensitive off:

apple
Apple
Zebra

Case-sensitive on:

apple
Apple
Zebra

Same output - because the only case difference in this sample is between "apple" and "Apple", and with the comparison turned off those two compare equal, so their original order is kept. Here is a sample where the toggle does change the answer:

Input:

apple
Banana
banana
apple

Case-sensitive off:

apple
apple
Banana
banana

Case-sensitive on:

apple
apple
banana
Banana

Now "Banana" and "banana" are no longer tied. The lower-case one came first. So the toggle is not "upper case before lower case" - it stops treating two spellings as the same value, and the order it then picks put the lower-case spelling first.

Run 4 - whitespace, blank lines and duplicates are left alone

Input (9 lines, 46 characters) - note the leading spaces on the first line, the two empty lines, the trailing spaces after "trailing", the repeated "line", and both spellings of "lead":

  lead
line


second
trailing  
line
line
Lead

Result:



  lead
Lead
line
line
line
second
trailing  

Four things to notice. The empty lines did not disappear - they sorted to the top, because an empty string sorts before any letter, and they are still in the output. The leading spaces on " lead" are kept, and they are why that line sorts above "Lead": a space sorts before a letter. The trailing spaces on "trailing" are kept in the output too. And the three "line" entries are all still there - Sort lines reorders, it never de-duplicates; removing duplicates is the separate Duplicate lines tab.

The bit that will bite you

Sorting is a comparison, and the comparison is not your editor's. Two things to watch. Whitespace is part of the value unless you clean it first - the Clean tab removes trailing spaces, trims outer whitespace and collapses repeated blank lines, so run it first on a list that came out of a copy-paste. And lines that compare equal keep their original order instead of being shuffled, which is why the two "apple" lines stay in place in the run above.

Where it runs

Text Studio is part of OnePassApps and it lives on the Text Studio page.

The whole thing happens in the tab: the file is read in the browser, the lines are compared there, and the sorted copy is written out on your own machine. Standard is free right now - $0/month, 100,000 credits every 30 days, no card required, and no automatic paid subscription.

Guides for the studios and the apps behind them are on the OnePassApps guides page.

Share