Lessons · Terminal · each stage sees only the one before
Each stage sees only the one before
A pipeline is read left to right and every stage is handed exactly what the stage before it printed -- never the original file.
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
Almost every wrong pipeline is a right pipeline in the wrong order.
How to think about it
Ask of each stage: what is arriving here? Then the order writes itself.
Worked example
cut -d' ' -f1 access.logJust the names now. The endpoints are gone, so nothing after this can group by endpoint.
cut -d' ' -f1 access.log | sort | uniq -cCounting what arrived: three from ada, two each from bo and cy.
cut -d' ' -f1 access.log | uniq -c | sortThe same three commands, reordered, and the answer is different and wrong: uniq counted runs before sort had grouped them.
Your turn
Group the lines of app.log before counting the repeats.
sort app.log | -c
Try it at a real prompt
The trap
uniq before sort is the commonest order mistake there is, and it does not error. It produces a smaller, plausible, incorrect answer.
Practise each stage sees only the one before on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.