Sort and Clean
Device
- Terminal
How
- Pipe output to
sortto alphabetize lines. - Use
sort -uto sort and remove all duplicate lines globally. - The
uniqcommand only removes adjacent duplicate runs; sort the input first, or usesort -uinstead. - Example:
printf 'apple\npear\napple\n' | uniqkeeps both apples;... | sort -ukeeps one.
Try this
Run printf 'apple\npear\napple\n' | uniq, then the same list piped to sort -u. Notice uniq alone does not collapse non-adjacent duplicates.
Why it works
Make messy lists usable.