3 ms·
Instead of { if($1 in count) { count[$1]=count[$1]+1 } else { count [$1] = 1 } } , {count[$1]++} does and means exactly the same thing. Why bother 'chan
by yesenadam 8y ago
Instead of
{ if($1 in count) { count[$1]=count[$1]+1 } else { count [$1] = 1 } } ,
{count[$1]++}
does and means exactly the same thing.
Why bother 'changing' the input field separator? No need. By default it's already space.
awk '{count[$1]++} END {for(k in count) print count[k],k}}'
- gerbilly 8y agoNeat. I wasn't sure what awk would do if there was no entry when it first encountered a new word. And yeah, I left the -F in there by mistake. But I don't get overly fussy with pipelines like this. I usually just hack them up as a one off then forget about them.