3 ms·
I love awk as much as the next person and I've written some pretty large scripts with it, but the original grep/sort/uniq is a lot easier to understand in two s
by arp242 3y ago
I love awk as much as the next person and I've written some pretty large scripts with it, but the original grep/sort/uniq is a lot easier to understand in two seconds. I don't think it's "useless" at all.
Also your awk isn't exactly identical as it's not sorted, but in this case that probably doesn't matter.
- j0hnyl 3y agoSame, I think I use grep | sort | uniq almost on the daily.
- dredmorbius 3y agoOne of the advantage of the array[item]++ / for (item in array) construct is that it avoids possibly expensive sorts (at the cost of generating potentially large arrays), and tends to be quite fast. That's even if you end up sorting the output by frequency, as the summary listing is typically shorter than the overall input data: {a[$1]++} END {for (i in array) printf("%6i %s\n", a[i], i) | "sort -k1nr | cat -n";} The accumulator/loop idiom is ... fairly readily recognisable to someone familiar with awk.