sort by line number and strip empty lines