Text tools

How to Sort Lines Alphabetically (Word, Excel, Docs, Notepad++)

Sort lines alphabetically online, or in Word, Excel, Google Docs, Notepad++ and Linux. Plus sorting by number or length, and why 10 comes before 2.

· 5 min read

To sort lines alphabetically, paste your list into our sort lines tool and choose A → Z. Every line is put in alphabetical order instantly, and numbers inside lines are sorted naturally, so "Item 2" comes before "Item 10". You can also sort Z to A, by number, by length, reverse the list or shuffle it. Nothing is uploaded; it all happens in your browser.

Here is how to do the same in Word, Excel, Google Docs, Notepad++ and the command line.

Sort lines online

  1. Paste your list, one item per line.
  2. Choose how to sort:
    • A → Z and Z → A: alphabetical, ignoring upper and lower case, with natural number order.
    • Numbers, low → high: for lines that start with a number, such as marks, prices or roll numbers.
    • Shortest first: by line length.
    • Reverse order: flips the list upside down without sorting it.
    • Shuffle: random order, useful for picking names or mixing quiz questions.
  3. Copy the result or download it as a .txt file.

If the list has repeats, run it through remove duplicate lines first. Our guide on removing duplicate lines explains the options. If the capitalisation is inconsistent, the case converter can make it uniform.

Sort lines alphabetically in Word

  1. Select the lines (each line must be its own paragraph, ending with Enter).
  2. On the Home tab, click Sort (the A-Z icon with a down arrow, in the Paragraph group).
  3. Set Sort by to Paragraphs and Type to Text.
  4. Choose Ascending (A to Z) or Descending (Z to A).
  5. Click OK.

Word can also sort a bulleted or numbered list the same way. To sort by a word other than the first (for example by surname), use Options to set a separator and choose that field.

Sort lines in Excel

  • Sort button: select the column, then Data > Sort A to Z (or Z to A). If the column is part of a table, Excel asks whether to expand the selection; choose Expand so each row stays together.
  • Custom sort: Data > Sort lets you sort by several columns, for example by city, then by name.
  • SORT function (Excel 365 and 2021): =SORT(A2:A200) returns a sorted copy without changing the original. =SORT(A2:A200,,-1) sorts descending.

Excel sorts rows, not the lines inside one cell. If a single cell holds a list separated by line breaks, copy the cell's contents into our sort lines tool, sort there and paste back.

Sort by date in Excel

Dates sort correctly only if Excel recognises them as dates. If "12/03/2026" sorts oddly, the column is probably stored as text. Convert it with Data > Text to Columns > Date (DMY) and sort again.

Sort lines alphabetically in Google Docs

Google Docs has no built-in sort. Options:

  • Copy the lines into a Google Sheets column, use Data > Sort range > A to Z, and paste them back.
  • Paste them into the sort lines tool and copy the result back.
  • Install a sorting add-on from Extensions > Add-ons > Get add-ons, if you do this often.

In Google Sheets, =SORT(A2:A100) works like Excel's.

Sort lines in Notepad++

Select the lines (or none, to sort the whole file), then Edit > Line Operations and choose:

  • Sort Lines Lexicographically Ascending/Descending: plain character order, case-sensitive.
  • Sort Lines Lex. Ascending Ignoring Case: alphabetical regardless of capitals.
  • Sort Lines As Integers Ascending or As Decimals: numeric order.

Recent versions also offer sorting by length and randomising.

Sort lines in VS Code

Select the lines, press Ctrl+Shift+P (Cmd+Shift+P on Mac) and run Sort Lines Ascending or Sort Lines Descending. This sort is by character order, so capital letters and numbers may group differently from a natural sort.

Sort lines in a file on Linux and Mac

Command What it does
sort file.txt Alphabetical
sort -f file.txt Ignore case
sort -r file.txt Reverse (Z to A)
sort -n file.txt Numeric, for lines starting with numbers
sort -V file.txt Natural "version" order, so 2 before 10
sort -u file.txt Sort and remove duplicates
awk '{print length, $0}' file.txt | sort -n | cut -d' ' -f2- By line length

In Vim, :sort sorts the buffer, :sort n sorts numerically and :sort u removes duplicates.

Why sorting results look wrong

10 comes before 2

Plain alphabetical sorting compares one character at a time. "10" starts with "1", which comes before "2", so "Chapter 10" lands before "Chapter 2". Natural sorting treats the number as a whole. Our A → Z option sorts naturally; in Linux use sort -V; in Excel, put the numbers in their own column and sort by that.

Capital letters come first

In strict character order (Notepad++'s plain lexicographic sort, VS Code, sort in some locales), all capitals can come before all lowercase letters, so "Zebra" comes before "apple". Use an "ignore case" option, or our tool, which ignores case.

Lines with leading spaces jump to the top

A space sorts before letters. Trim the lines first; remove duplicate lines with "Trim spaces" on does this and removes repeats at the same time.

Accented or non-English names

Our tool uses your browser's language-aware comparison, so accented letters sort next to their plain versions. Hindi and other scripts sort by that script's order. Simple tools that sort by character code may put them in unexpected places.

"Numbers, low → high" on mixed lines

This option reads the number at the start of each line. Lines that do not start with a number cannot be compared and may end up anywhere. Use A → Z for mixed text; its natural ordering still handles numbers inside words.

Common mistakes

  • Sorting one Excel column of a table on its own, so names no longer match their marks or phone numbers. Always expand the selection.
  • Sorting dates stored as text, which sorts by day number rather than by date.
  • Expecting Google Docs to have a sort button. Use Sheets or a sorting tool.
  • Forgetting to remove blank lines, which all collect at the top of the sorted list.

Questions

How do I sort lines alphabetically in Word?

Select the lines, click Sort (the A-Z arrow icon) on the Home tab, choose Sort by Paragraphs and Type Text, pick Ascending, and click OK.

Can Google Docs sort lines alphabetically?

Not on its own. Google Docs has no built-in sort. Paste the lines into a sorting tool or a Google Sheets column, sort them there, and paste them back, or install a sorting add-on.

Why does 10 come before 2 when I sort?

Simple alphabetical sorting compares text one character at a time, and '1' comes before '2'. A natural or numeric sort reads the whole number, so 2 comes before 10.

How do I sort lines by length?

Choose 'Shortest first' in our sort lines tool. On Linux or Mac, use awk '{print length, $0}' file.txt | sort -n | cut -d' ' -f2-.

Related guides

All guides