5 ms·
And what if the strings are separated by spaces instead of newlines?
by amelius 9y ago
And what if the strings are separated by spaces instead of newlines?
- flerchin 9y agosed foo -e 's/ /\n/g' | sort | uniq
- amelius 9y agoYeah, but what if the strings I wanted to sort contain newlines?
- flerchin 9y agoYou haven't specified a delimiter.
- jws 9y 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 9y agoecho "Input file already sorted."
- stepvhen 9y agoprotip: tr ' ' '\n' < foo | sort | uniq
- innagadadavida 9y agoIf you want to preserve order, this is how you uniq with awk: awk '!x[$0]++'
- deleted 9y ago[deleted]