Remove duplicate lines and optionally sort.