Hone

Lessons · Terminal · the ten commonest values

The ten commonest values

Cut the column, sort so duplicates meet, count them, sort those counts as numbers biggest first, take the top.

Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.

What it is for

Five stages that answer a startling number of questions with nothing changed but the column number.

How to think about it

Build it up one stage at a time and look at each.

Worked example

cut -d' ' -f1 access.log
Stage one: just the names.
cut -d' ' -f1 access.log | sort | uniq -c
Grouped and counted.
cut -d' ' -f1 access.log | sort | uniq -c | sort -rn | head -n 2
Ranked and topped. The whole idiom.

Your turn

Rank those counts with the biggest first.

sort app.log | uniq -c | sort 

The trap

Every stage matters and the order is not negotiable. sort before uniq, and -n on the final sort.

Practise the ten commonest values on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.