Sort Rows

The sort command reorganizes lines in a text file or standard output (technically the same thing) so they are arranged numerically and alphabetically.

Create Example File With List Of Names

echo 'Luca Gartside' >> adventurers.txt
echo 'Reule Smyth' >> adventurers.txt
echo 'Spencer Smit' >> adventurers.txt
echo 'Crurnirk Steelflow' >> adventurers.txt
echo 'Uli Pinetotem' >> adventurers.txt
echo 'Lai Zhi Lightdream' >> adventurers.txt

View File

cat adventurers.txt
Luca Gartside
Reule Smyth
Spencer Smit
Crurnirk Steelflow
Uli Pinetotem
Lai Zhi Lightdream

Sort List Of Names And Write To New File

sort adventurers.txt > adventurers_sorted.txt

View Sorted File

cat adventurers_sorted.txt
Crurnirk Steelflow
Lai Zhi Lightdream
Luca Gartside
Reule Smyth
Spencer Smit
Uli Pinetotem

Alternative: Reverse Sort

sort -r adventurers.txt
Uli Pinetotem
Spencer Smit
Reule Smyth
Luca Gartside
Lai Zhi Lightdream
Crurnirk Steelflow