Text Tools & UtilitiesSpecialized Version
📝

Sort Text Lines Alphabetically

Sort lines A-Z

Sort Text Lines Alphabetically

Organize your text with our alphabetical line sorter. Whether you're arranging names, organizing lists, or sorting data exports, this tool provides instant A-Z (or Z-A) sorting with options for case sensitivity, numeric awareness, and locale-specific ordering.

Sorting Options

| Sort Type | Example Result | Best For | A-Z (Ascending)Apple, Banana, CherryStandard alphabetical Z-A (Descending)Cherry, Banana, AppleReverse order Case Insensitiveapple, Apple, APPLE togetherMixed case lists Natural/Numericfile1, file2, file10Numbered items | Locale-Aware | á after a, ñ after n | International text |

Text Line Sorting Algorithm

``javascript function sortLinesAlphabetically(text, options = {}) { const { order = 'asc', caseSensitive = false, naturalSort = false, locale = 'en' } = options;

let lines = text.split('\n').filter(line => line.trim());

if (naturalSort) { // Natural sorting: file1, file2, file10 (not file1, file10, file2) lines.sort((a, b) => a.localeCompare(b, locale, { numeric: true, sensitivity: 'base' })); } else { lines.sort((a, b) => { const compareA = caseSensitive ? a : a.toLowerCase(); const compareB = caseSensitive ? b : b.toLowerCase(); return compareA.localeCompare(compareB, locale); }); }

if (order === 'desc') lines.reverse();

return { sortedLines: lines.length, result: lines.join('\n') }; } ``

Natural vs. Lexicographic Sorting

Standard alphabetical sorting treats numbers as text: "file10" comes before "file2" because "1" < "2" character-by-character. Natural sorting understands numbers: "file2" correctly comes before "file10". Enable natural sorting for filenames, version numbers, or any list with numeric components.

International Sorting

Different languages have different sorting rules. In Spanish, "ñ" sorts after "n". In Swedish, "ö" comes at the end of the alphabet. Our locale-aware sorting respects these conventions. Select your locale for accurate international text sorting.

Frequently Asked Questions

How do I sort text alphabetically?

Paste your text into the sorter and lines will be automatically arranged A to Z. Choose ascending (A-Z) or descending (Z-A) order. Enable case-insensitive mode if you want "apple" and "Apple" sorted together.

Why does file10 sort before file2?

Standard alphabetical sorting compares characters: "1" < "2", so "file10" comes first. Enable "natural sorting" to treat embedded numbers as values, correctly placing "file2" before "file10".

Can I sort while removing duplicates?

Yes, use the sort tool first to organize your lines, then use the duplicate remover to eliminate repeated entries. Or enable both options simultaneously if the tool supports combined operations.

Related Tools

Explore other tools you might find useful:

Related Calculators