6 ms·
/me wonders are candidates allowed to chose their favorite language? man bash | tr '[:upper:] ' '[:lower:]\n' | sed '/^$/d' | sort | uniq -c | sort -rn | head
by kephra 13y ago
/me wonders
are candidates allowed to chose their favorite language?
man bash | tr '[:upper:] ' '[:lower:]\n' | sed '/^$/d' | sort | uniq -c | sort -rn | head | awk '{ print $2 }' | fmt
or do you only hire windows coders?
- dpritchett 13y agoIt sounds like OP has been writing C# for ten years straight, so I'd guess there's a certain level of Windows/MSSQL/.NET experience expected.
- kyllo 13y agoPerhaps, if you did it in Powershell?
- epistasis 13y agoThis is how I do this sort of thing all the time. But, the sort is O(n log n), so it's asymptotically less satisfying.
- kephra 13y agoTrue, a bag of words would perform better. man bash | tr '[:upper:] ' '[:lower:]\n' | awk '/./ { bag[$1]++ } END { for(word in bag) { print bag[word], word } }' | sort -rn | awk '{ print } NR>=10 { exit(0) }' But it would require more typing and thinking. sure one could do this in awk completely, man bash | awk ' /./ { for (i = 1; i<=NF; i++) { bag[tolower($i)]++ } } END { for (i = 1; i<=10; i++) { score=0; for(word in bag) { if (bag[word] > score) { score=bag[word]; best=word } } printf "%s ", best delete bag[best] } printf "\n" }' if the requirement is: please chose one language and not the complete Unix babylon.
- grannyg00se 13y agoAwesome. I was going to post my two line javascript version, but instead I'm going to study this. There are three commands I've never heard of there. And it's definitely time to take a first crack at awk.
- anonymous 13y agoYou don't need that tr, just sort -f and then uniq -i. Of course, whoever put -f as the ignore-case flag for sort should be shot methinks, or rather the one who first added -i as "ignore nonprinting characters". Edit: and while we're on the subject, you can get rid of head and use awk 'NR<=10 {print $2}' Edit²: I would also like to point out that your version is superior to any short C# program, because sort can sort sequences that exceed the amount of RAM you have.
- mzs 13y agoI should have looked below, I wrote a similar thing above, but you forgot to split multiple words in a line to lines. That's okay, a lot of people above forgot to about case and punctuation even!