Actually, my solution in the end was to redirect the output to a different file:
rankmirrors $mirror > ${mirror}_new
and then to rename it following the sorting operations:
While of course first making a ${mirror}.bak of every file first.
Thanks for all the advice. I've actually just purchased O'Reilly's "Classic Shell Scripting" which covers Awk, Sed, and Bash in detail. I figured it was about time.
