Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Define "word". However, strings separated by space:

Print number of words:

    wc -w <filename>
Print words with counts in decreasing order:

    cat <filename>  \
    | gawk '{for (i=1;i<=NF;i++) print $i}' \
    | sort          \
    | uniq -c       \
    | sort -rn      \
    | less
There are optimizations to be made, but that would be my go to solution in the first instance.


Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: