Online
The quickest way is the sort lines tool. Paste your lines, choose a method and copy the result. There are dedicated pages for alphabetical, reverse, numerical and length sorting.
Linux and macOS
sort file.txt # alphabetical
sort -r file.txt # reverse
sort -n file.txt # numeric
sort -u file.txt # sort and remove duplicates
sort -f file.txt # ignore caseThe sort command depends on your locale. Running it as LC_ALL=C sort uses plain character order, which puts capital letters before lowercase ones.
Windows PowerShell
Get-Content file.txt | Sort-Object
Get-Content file.txt | Sort-Object -Descending
Get-Content file.txt | Sort-Object { [int]$_ }VS Code and Excel
In VS Code, open the Command Palette and run Sort Lines Ascending or Sort Lines Descending. In Excel, put one item per cell in a column and use Data, then Sort A to Z.
Python
lines = text.splitlines()
sorted(lines) # alphabetical
sorted(lines, key=len) # by length
sorted(lines, key=float) # numeric, if every line is a numberCommon mistakes
- Numbers sorted as text: 10 lands before 2 unless you sort numerically.
- Case surprises: some tools put all capitals first.
- Blank lines: empty lines sort to the top, so remove them first.
- Trailing spaces: invisible spaces change the order. Trim lines before sorting.
Sort your own lines. Paste them in and choose alphabetical, numeric, reverse or length order.