Been using Emacs for years but still learning

M-x sort-lines
M-x delete-trailing-whitespace

I knew about the first command but not the second. Very handy to tidy up an ugly SQL*Plus spool file.