| ▲ | Snarwin 5 hours ago | |
> There's no native Unix equivalent to frequencies, this sort | uniq -c is the closest we can get. Not only is it less performant (it has to collect the full input into memory before continuing), but it ties aggregation to ordering. One of the core features of the Unix command-line is that it is user-extensible. If there's no "native" command equivalent to frequencies, you can write your own, and it will be given the same first-class treatment as any other binary in your PATH. This is entirely in keeping with the Unix philosophy of simple implementations. | ||
| ▲ | atiedebee 16 minutes ago | parent | next [-] | |
I imagine just ask would be enough for most usecases: awk '{ freq[$0] += 1 } END { for (n in freq ){ print freq[n] " " n } }' < file.txt | ||
| ▲ | diegocg 2 hours ago | parent | prev [-] | |
Yeah, that point was weak. The argument went from "Unix pipelines are not simple" to "unix based operating systems don't have an equivalent to Clojure's frequency function by default so it's worse" OK but how would it look like if you had such a program? Shells are not known for having the extensive set of functions that real programming languages have. | ||