5 ms·
sed foo -e 's/ /\n/g' | sort | uniq
by flerchin 8y ago
sed foo -e 's/ /\n/g' | sort | uniq
- amelius 8y agoYeah, but what if the strings I wanted to sort contain newlines?
- flerchin 8y agoYou haven't specified a delimiter.
- jws 8y agoYou (sir|madam), are a feature creep. If it weren’t for people like you and their “real requirements” software would be easy. By the time you say “unicode” and “collation” the programmer is going to be in serious trouble. Fortunately the programmer can lawyer the problem. The original requirements don’t specify what the strings are sorted by. I choose “position in original source” file and complete the task with a NOP.
- diegoperini 8y agoecho "Input file already sorted."
- stepvhen 8y agoprotip: tr ' ' '\n' < foo | sort | uniq
- innagadadavida 8y agoIf you want to preserve order, this is how you uniq with awk: awk '!x[$0]++'