One line solution with awk


  • 0
    A
    awk '{for(i=1;i<=NF;i++){arr[$i] +=1;}}END{for(tmp in arr){print tmp" "arr[tmp]}}' words.txt| sort -k2nr
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.