[{"data":1,"prerenderedAt":834},["ShallowReactive",2],{"blog-uk-sort-lines-alphabetically":3},{"id":4,"title":5,"alt":6,"author":7,"body":8,"category":798,"description":799,"extension":800,"faq":801,"image":820,"meta":821,"navigation":822,"path":823,"publishedAt":824,"seo":825,"stem":826,"tags":827,"__hash__":833},"blog\u002Fen\u002Fsort-lines-alphabetically.md","Sort Lines Alphabetically: VS Code, Terminal & Online","A scrambled stack of text lines being reordered into A-to-Z alphabetical order with a green sort indicator on a slate background","Vibe Apps Pro Team",{"type":9,"value":10,"toc":782},"minimark",[11,29,35,40,55,70,102,132,139,143,157,179,196,200,206,315,335,355,359,362,416,429,504,513,516,656,660,667,691,695,700,716,720,734,738,767,771],[12,13,14,15,19,20,23,24,28],"p",{},"To sort lines alphabetically, you've got three solid options: paste your list into an ",[16,17,18],"strong",{},"online sorter"," and click A→Z, run ",[16,21,22],{},"Sort Lines Ascending"," from the VS Code Command Palette, or pipe a file through ",[25,26,27],"code",{},"sort"," in the terminal. All three work. The twist nobody mentions is that they don't always agree — case-sensitivity and locale settings quietly change the order you get back.",[12,30,31,32,34],{},"That's the part that bites you. You sort a list in VS Code, sort the \"same\" list on a colleague's machine with ",[25,33,27],{},", and the two outputs differ. Neither is broken. They're just using different collation rules. Let's get the order you actually want, in whichever environment you're in.",[36,37,39],"h2",{"id":38},"the-fastest-path-sort-online","The Fastest Path: Sort Online",[12,41,42,43,50,51,54],{},"For a one-off list, skip the tooling. Paste it into our ",[16,44,45],{},[46,47,49],"a",{"href":48},"\u002Fsort-lines","Sort Lines"," — it runs 100% in your browser, zero data sent to any server — and pick ",[16,52,53],{},"Sort A→Z",". Every newline is one item, so names, URLs, ES imports, log lines, or CSV rows all alphabetize in a single click.",[12,56,57,58,61,62,65,66,69],{},"Under the hood it uses JavaScript's ",[25,59,60],{},"String.prototype.localeCompare"," — ",[16,63,64],{},"locale-aware collation",", not a naïve byte comparison. That's the same ICU-backed ordering your operating system uses, so accented characters and punctuation land where a human expects them, not dumped after ",[25,67,68],{},"z",". A few specifics:",[71,72,73,80,86,92],"ul",{},[74,75,76,79],"li",{},[16,77,78],{},"Sort A→Z \u002F Z→A"," — ascending or descending, your call.",[74,81,82,85],{},[16,83,84],{},"Case-sensitive toggle"," — off by default (dictionary order); flip it on to group capitals separately.",[74,87,88,91],{},[16,89,90],{},"By length"," — shortest-first or longest-first, handy for spotting outliers in a list.",[74,93,94,97,98,101],{},[16,95,96],{},"Shuffle"," — randomizes order with a ",[16,99,100],{},"Fisher-Yates"," shuffle (the unbiased one, O(n)), useful for sampling or breaking up a sorted bias.",[12,103,104,105,108,109,112,113,116,117,120,121,124,125,127,128,131],{},"One thing to know up front: this is a ",[16,106,107],{},"text"," sort, so numbers order lexicographically — ",[25,110,111],{},"10"," lands before ",[25,114,115],{},"2",", because it compares character by character. If your list is numeric, ",[16,118,119],{},"zero-pad it"," (",[25,122,123],{},"02",", ",[25,126,111],{},") so text order and numeric order line up. For native numeric ordering you want the terminal's ",[25,129,130],{},"sort -n"," instead — covered below.",[12,133,134,135,138],{},"The sort is ",[16,136,137],{},"stable",", too — lines that compare equal keep their original relative order, which matters when you sort by length and want ties left alone.",[36,140,142],{"id":141},"sorting-lines-in-vs-code","Sorting Lines in VS Code",[12,144,145,146,149,150,152,153,156],{},"VS Code has this built in — no extension needed for the basics. Select your lines (or don't, to sort the whole file), open the Command Palette with ",[25,147,148],{},"Cmd\u002FCtrl + Shift + P",", type \"Sort Lines\", and choose ",[16,151,22],{}," or ",[16,154,155],{},"Sort Lines Descending",".",[12,158,159,160,163,164,167,168,171,172,178],{},"Here's the limitation that trips people up: ",[16,161,162],{},"the built-in command is strictly case-sensitive",", and it offers no numeric sort and no duplicate removal. So ",[25,165,166],{},"Banana"," sorts before ",[25,169,170],{},"apple"," every time, with no toggle to change it. This has been a long-standing request (",[46,173,177],{"href":174,"rel":175},"https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fvscode\u002Fissues\u002F18315",[176],"nofollow","microsoft\u002Fvscode#18315",").",[12,180,181,182,185,186,189,190,156],{},"If you need case-insensitive order, numeric sort, or dedup-while-sorting, install the ",[16,183,184],{},"Tyriar \"Sort lines\""," extension. It adds those modes and binds sorting to ",[25,187,188],{},"F9",". Many devs pair sorting with deduplication — if that's you, the same workflow and edge cases are covered in our guide to ",[16,191,192],{},[46,193,195],{"href":194},"\u002Fblog\u002Fhow-to-remove-duplicate-lines-vscode","removing duplicate lines in VS Code",[36,197,199],{"id":198},"sorting-lines-in-the-terminal","Sorting Lines in the Terminal",[12,201,202,203,205],{},"The Unix ",[25,204,27],{}," command is the workhorse, but its default behavior is locale-dependent — which is exactly why two machines disagree.",[207,208,209,223],"table",{},[210,211,212],"thead",{},[213,214,215,220],"tr",{},[216,217,219],"th",{"align":218},"left","Command",[216,221,222],{"align":218},"What it does",[224,225,226,241,255,268,291,301],"tbody",{},[213,227,228,234],{},[229,230,231],"td",{"align":218},[25,232,233],{},"sort file.txt",[229,235,236,237,240],{"align":218},"Sort lines using the current locale's collation (",[25,238,239],{},"LC_COLLATE",")",[213,242,243,248],{},[229,244,245],{"align":218},[25,246,247],{},"LC_ALL=C sort file.txt",[229,249,250,251,254],{"align":218},"Sort in raw ",[16,252,253],{},"byte order"," (capitals before lowercase) — deterministic",[213,256,257,262],{},[229,258,259],{"align":218},[25,260,261],{},"sort -f file.txt",[229,263,264,267],{"align":218},[16,265,266],{},"Fold case"," — case-insensitive dictionary order",[213,269,270,275],{},[229,271,272],{"align":218},[25,273,274],{},"sort -n file.txt",[229,276,277,280,281,283,284,287,288,240],{"align":218},[16,278,279],{},"Numeric"," sort (so ",[25,282,111],{}," comes after ",[25,285,286],{},"9",", not after ",[25,289,290],{},"1",[213,292,293,298],{},[229,294,295],{"align":218},[25,296,297],{},"sort -r file.txt",[229,299,300],{"align":218},"Reverse (Z→A)",[213,302,303,308],{},[229,304,305],{"align":218},[25,306,307],{},"sort -u file.txt",[229,309,310,311,314],{"align":218},"Sort ",[16,312,313],{},"and remove duplicates"," in one pass",[12,316,317,318,124,321,323,324,327,328,331,332,156],{},"The headline gotcha: on a machine set to ",[25,319,320],{},"en_US.UTF-8",[25,322,27],{}," mostly ignores case and punctuation in its primary comparison; on a box running ",[25,325,326],{},"LC_ALL=C",", it sorts by byte value, where every uppercase letter precedes every lowercase one. ",[16,329,330],{},"Same file, same command, different output."," When you need a result that's identical everywhere — a checked-in fixture, a diffable manifest — pin it with ",[25,333,334],{},"LC_ALL=C sort",[12,336,337,338,341,342,124,345,348,349,352,353,156],{},"PowerShell users have the equivalent in ",[25,339,340],{},"Get-Content file.txt | Sort-Object"," (add ",[25,343,344],{},"-Unique",[25,346,347],{},"-Descending",", or ",[25,350,351],{},"-CaseSensitive"," as needed); it's case-insensitive by default, the opposite of ",[25,354,326],{},[36,356,358],{"id":357},"the-real-reason-your-orders-differ-case-collation","The Real Reason Your Orders Differ: Case & Collation",[12,360,361],{},"This is the concept that ties all three tools together. There are two ways to compare two strings:",[363,364,365,398],"ol",{},[74,366,367,370,371,374,375,378,379,374,381,383,384,387,388,391,392,394,395,397],{},[16,368,369],{},"Code-point order"," — compare raw character codes. In ASCII, ",[25,372,373],{},"A","–",[25,376,377],{},"Z"," are 65–90 and ",[25,380,46],{},[25,382,68],{}," are 97–122, so ",[16,385,386],{},"every capital sorts before every lowercase letter",". ",[25,389,390],{},"Zebra"," (90…) beats ",[25,393,170],{}," (97…). This is what ",[25,396,334],{}," and VS Code's built-in command do.",[74,399,400,403,404,407,408,411,412,415],{},[16,401,402],{},"Locale-aware collation"," — fold case and weight characters the way a dictionary does: apple, Banana, cherry, Zebra. This is what ",[25,405,406],{},"localeCompare"," (our tool), ",[25,409,410],{},"sort -f",", and ",[25,413,414],{},"Sort-Object"," do.",[12,417,418,419,124,421,124,423,124,426,428],{},"Here's the same four-item list — ",[25,420,170],{},[25,422,166],{},[25,424,425],{},"cherry",[25,427,390],{}," — sorted both ways:",[207,430,431,452],{},[210,432,433],{},[213,434,435,439,445],{},[216,436,438],{"align":437},"center","#",[216,440,441,442,444],{"align":218},"Code-point order (",[25,443,326],{},", VS Code built-in)",[216,446,447,448,124,450,240],{"align":218},"Dictionary order (",[25,449,406],{},[25,451,410],{},[224,453,454,466,478,491],{},[213,455,456,458,462],{},[229,457,290],{"align":437},[229,459,460],{"align":218},[25,461,166],{},[229,463,464],{"align":218},[25,465,170],{},[213,467,468,470,474],{},[229,469,115],{"align":437},[229,471,472],{"align":218},[25,473,390],{},[229,475,476],{"align":218},[25,477,166],{},[213,479,480,483,487],{},[229,481,482],{"align":437},"3",[229,484,485],{"align":218},[25,486,170],{},[229,488,489],{"align":218},[25,490,425],{},[213,492,493,496,500],{},[229,494,495],{"align":437},"4",[229,497,498],{"align":218},[25,499,425],{},[229,501,502],{"align":218},[25,503,390],{},[12,505,506,507,509,510,512],{},"See how ",[25,508,390],{}," jumps to the top on the left? That's the capital ",[25,511,377],{}," (code point 90) outranking the lowercase letters (97+) — the single most common \"why is my sort wrong\" moment.",[12,514,515],{},"Neither is \"wrong\" — but you have to know which one you're invoking, or you'll chase a phantom bug. If your sorted list looks like it put all the capitalized entries in a clump at the top, you're getting code-point order and probably want case-insensitive instead.",[207,517,518,540],{},[210,519,520],{},[213,521,522,525,528,531,534,537],{},[216,523,524],{"align":218},"Method",[216,526,527],{"align":437},"Case-insensitive?",[216,529,530],{"align":437},"Numeric sort?",[216,532,533],{"align":437},"Dedup?",[216,535,536],{"align":437},"Reverse?",[216,538,539],{"align":437},"Offline \u002F private",[224,541,542,564,583,600,631],{},[213,543,544,549,552,555,558,561],{},[229,545,546],{"align":218},[16,547,548],{},"Online (Sort Lines)",[229,550,551],{"align":437},"Toggle",[229,553,554],{"align":437},"—",[229,556,557],{"align":437},"via Remove Duplicates",[229,559,560],{"align":437},"Yes",[229,562,563],{"align":437},"Yes (in-browser)",[213,565,566,571,574,577,579,581],{},[229,567,568],{"align":218},[16,569,570],{},"VS Code built-in",[229,572,573],{"align":437},"No (always case-sensitive)",[229,575,576],{"align":437},"No",[229,578,576],{"align":437},[229,580,560],{"align":437},[229,582,560],{"align":437},[213,584,585,590,592,594,596,598],{},[229,586,587],{"align":218},[16,588,589],{},"VS Code + Tyriar ext.",[229,591,560],{"align":437},[229,593,560],{"align":437},[229,595,560],{"align":437},[229,597,560],{"align":437},[229,599,560],{"align":437},[213,601,602,609,614,619,624,629],{},[229,603,604],{"align":218},[16,605,606,607],{},"Terminal ",[25,608,27],{},[229,610,611],{"align":437},[25,612,613],{},"-f",[229,615,616],{"align":437},[25,617,618],{},"-n",[229,620,621],{"align":437},[25,622,623],{},"-u",[229,625,626],{"align":437},[25,627,628],{},"-r",[229,630,560],{"align":437},[213,632,633,640,643,646,650,654],{},[229,634,635],{"align":218},[16,636,637,638],{},"PowerShell ",[25,639,414],{},[229,641,642],{"align":437},"Default",[229,644,645],{"align":437},"Auto on numbers",[229,647,648],{"align":437},[25,649,344],{},[229,651,652],{"align":437},[25,653,347],{},[229,655,560],{"align":437},[36,657,659],{"id":658},"clean-before-you-sort","Clean Before You Sort",[12,661,662,663,666],{},"One last trap. Sorting is only as good as the lines you feed it, and pasted text is rarely clean. A trailing space, a non-breaking space (",[25,664,665],{},"U+00A0",") from a web copy, or a stray tab will sort an item to an unexpected spot — and will keep \"duplicate\" lines from collapsing because they aren't byte-identical.",[12,668,669,670,676,677,683,684,690],{},"Run the list through our ",[16,671,672],{},[46,673,675],{"href":674},"\u002Fremove-spaces","Remove Spaces"," tool first to strip trailing whitespace and exotic Unicode spaces; the full list of contaminants that hitchhike on pasted text is broken down in ",[16,678,679],{},[46,680,682],{"href":681},"\u002Fblog\u002Fhow-to-remove-extra-spaces-from-text-online","how to remove extra spaces from text online",". Then sort. Then, if you need uniqueness, run it through ",[16,685,686],{},[46,687,689],{"href":688},"\u002Fremove-duplicates","Remove Duplicates",". Clean → sort → dedup is the reliable pipeline.",[36,692,694],{"id":693},"frequently-asked-questions","Frequently Asked Questions",[696,697,699],"h3",{"id":698},"does-sorting-work-with-non-english-characters","Does sorting work with non-English characters?",[12,701,702,703,705,706,708,709,712,713,715],{},"Yes. The online tool's ",[25,704,406],{}," is Unicode-aware, so Cyrillic, accented Latin, and other scripts collate sensibly rather than being shoved past ",[25,707,68],{},". In the terminal, accurate non-ASCII ordering depends on a UTF-8 locale (e.g. ",[25,710,711],{},"LC_COLLATE=en_US.UTF-8","); under ",[25,714,326],{}," you get byte order, which splits multibyte characters in ways that rarely match human expectations.",[696,717,719],{"id":718},"can-i-sort-a-huge-list-without-freezing-my-browser","Can I sort a huge list without freezing my browser?",[12,721,722,723,726,727,730,731,733],{},"For typical lists — even tens of thousands of lines — an in-browser sort resolves in well under a second, because ",[25,724,725],{},"Array.prototype.sort"," is highly optimized in V8. The cost is the comparison count (",[25,728,729],{},"O(n log n)","), not network latency, since nothing is uploaded. Genuinely massive files (hundreds of MB) are still better handled by the streaming ",[25,732,27],{}," command on disk.",[696,735,737],{"id":736},"why-isnt-my-numeric-list-sorting-correctly","Why isn't my numeric list sorting correctly?",[12,739,740,741,167,743,745,746,748,749,752,753,755,756,758,759,761,762,124,764,766],{},"Alphabetical sorting is text-based, so ",[25,742,111],{},[25,744,115],{}," (it compares ",[25,747,290],{}," then ",[25,750,751],{},"0"," against ",[25,754,115],{},"). That's not a bug — it's lexicographic order. For true numeric order, use ",[25,757,130],{}," in the terminal, or PowerShell's ",[25,760,414],{},", which detects numbers automatically. Within a text-only sorter, zero-pad your numbers (",[25,763,123],{},[25,765,111],{},") so lexicographic and numeric order coincide.",[36,768,770],{"id":769},"sort-it-then-move-on","Sort It, Then Move On",[12,772,773,774,776,777,781],{},"Pick the tool that matches the moment: the Command Palette when you're already in VS Code, ",[25,775,27],{}," when you're in a shell and need it scripted, and the ",[16,778,779],{},[46,780,49],{"href":48}," tool when you just want a list alphabetized without thinking about locales or installing anything. Whatever you choose, decide up front whether you want case-sensitive or dictionary order — that single choice explains almost every \"weird\" sort result you'll ever hit.",{"title":783,"searchDepth":784,"depth":784,"links":785},"",2,[786,787,788,789,790,791,797],{"id":38,"depth":784,"text":39},{"id":141,"depth":784,"text":142},{"id":198,"depth":784,"text":199},{"id":357,"depth":784,"text":358},{"id":658,"depth":784,"text":659},{"id":693,"depth":784,"text":694,"children":792},[793,795,796],{"id":698,"depth":794,"text":699},3,{"id":718,"depth":794,"text":719},{"id":736,"depth":794,"text":737},{"id":769,"depth":784,"text":770},"Dev Tools","Sort lines alphabetically in VS Code, the terminal, or online — plus the case-sensitivity and locale gotchas that quietly change your results. Sort yours now.","md",[802,805,808,811,814,817],{"question":803,"answer":804},"How do I sort lines alphabetically online?","Paste your list into the [Sort Lines tool](\u002Fsort-lines), choose Sort A→Z, and copy the result — that's the whole flow. Each newline is treated as one item, so a list of names, URLs, imports, or CSV rows sorts in one click. Toggle case-sensitivity on if you need capitals grouped separately, or leave it off for normal dictionary order. Nothing uploads: the sort runs in your browser, so even a confidential list of emails or internal hostnames never leaves your machine.",{"question":806,"answer":807},"Does VS Code sort lines alphabetically without an extension?","Yes. VS Code ships built-in commands — open the Command Palette (Cmd\u002FCtrl+Shift+P), type 'Sort Lines', and pick Sort Lines Ascending or Descending. There's no default keyboard shortcut, so you go through the palette each time. The catch is that the built-in sort is strictly case-sensitive and offers no numeric sort and no duplicate removal. For case-insensitive order, numeric sort, or dedup, install the Tyriar 'Sort lines' extension, which also binds the action to F9.",{"question":809,"answer":810},"Why does the terminal sort command give different results on another machine?","Because GNU sort respects your locale's collation rules through the LC_COLLATE environment variable. On a machine set to en_US.UTF-8, sort largely ignores case and punctuation in the primary comparison; on a machine running LC_ALL=C, sort falls back to raw byte order, where every uppercase letter sorts before every lowercase letter. Same file, same command, different output. Run LC_ALL=C sort file.txt when you need deterministic, reproducible byte-order results across environments.",{"question":812,"answer":813},"How do I sort lines and remove duplicates at the same time?","In the terminal, sort -u file.txt sorts and drops duplicate lines in a single pass. Online, sort first with the Sort Lines tool, then run the result through the [Remove Duplicates tool](\u002Fremove-duplicates) — or do it in either order, since both are line-based. Watch for invisible whitespace: a trailing space or a non-breaking space makes two 'identical' lines count as different, so they survive the dedup. Clean the text first if your duplicates aren't collapsing.",{"question":815,"answer":816},"What's the difference between case-sensitive and case-insensitive sorting?","Case-sensitive sorting compares the underlying character codes, so capital letters (code points 65–90) all rank before lowercase letters (97–122) — 'Zebra' lands before 'apple'. Case-insensitive sorting folds both to the same case first, giving the dictionary order most people expect: apple, Banana, cherry, Zebra. The Sort Lines tool exposes this as a toggle; the terminal uses sort -f to fold case; VS Code's built-in command is always case-sensitive.",{"question":818,"answer":819},"Is my data uploaded when I sort lines online?","No. The Sort Lines tool runs entirely as client-side JavaScript — your list is sorted in the browser tab and never transmitted to a server. There's no account, no logging, and no stored copy. This matters when you're alphabetizing something sensitive: a list of customer emails, internal API endpoints, employee names, or unreleased product SKUs. Close the tab and the data is gone from memory, because the server never received it in the first place.","\u002Farticles\u002Fsort-lines-alphabetically\u002Fhero.webp",{},true,"\u002Fen\u002Fsort-lines-alphabetically","2026-05-27",{"title":5,"description":799},"en\u002Fsort-lines-alphabetically",[828,829,830,831,832],"sort lines alphabetically","sort lines online","vscode sort lines","terminal sort","dev tools","N4ZY06HINbYTV2QMjeMYPhZLCz8XHdmlR_SY6wUWrHY",1782712869940]