/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?
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?
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.
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.