Hacker News new | past | comments | ask | show | jobs | submit login

I use "sort | uniq -c" all the time, but I find it annoying that it does it in worse-than-linear time. It gets super slow every time I accidentally pass it a large input.

At that point I usually fall back to "awk '{ xs[$0]++ } END { for (x in xs) print xs[x], x }'", but it's quite long and awkward to type, so I don't do it by default every time.

At some point I'll add an alias or a script to do this. One day.

edit: OK I finally did it; it's literally been on my to-do list for about 10 years now, so thanks :)

$ cat ~/bin/count

#!/usr/bin/awk -f

{ xs[$0]++ } END { for (x in xs) print xs[x], x }




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

Search: