3 ms·
j_z_reeves 9 hours ago [-] > cat logfile | awk '/ERROR:/ {counts[$1] = counts[$1] + 1}; END { for (day in counts) print day " : " counts[day]}' | sort Great
by tejtm 6y ago
j_z_reeves 9 hours ago [-]
> cat logfile | awk '/ERROR:/ {counts[$1] = counts[$1] + 1}; END { for (day in counts) print day " : " counts[day]}' | sort
Great first program! a bit less verbose could be
> awk '/ERROR:/ {counts[$1]++}END{...}' logfile
there are also ways of sorting the output but within (g)awk (asort & asorti) but sorting externally as you have is more flexible and engages another core which can be faster on large input