sort command, as the name suggests sorts the lines alphabetically and numerically, automatically. All you got to do is pipe the stdin into sort command.

Important Flags for sort:

FlagsDescription
-rSorts in reverse order
-cThis flag is used to check whether the file is already sorted or not(If not, it will list, where the disorder started)
-uTo sort and removes duplicate lines(does work same as stdin redirected into uniq)
-o save.txtTo save into a output file