Hone

Lessons · Terminal · build a pipeline one stage at a time

Build it one stage at a time

Write one command, look at it, add the next. A pipeline you built up is a pipeline you can debug.

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

A five-stage pipeline typed whole gives you one wrong answer and no clue which stage produced it.

How to think about it

Add | head while you are working so you see the shape without waiting, and take it off at the end.

Worked example

cut -d' ' -f2 access.log | head -n 3
Stage one, three lines of it. Endpoints, as expected.
cut -d' ' -f2 access.log | sort | head -n 3
Stage two. Grouped now.
cut -d' ' -f2 access.log | sort | uniq -c | sort -rn
The finished thing, and every stage on the way was checked.

Your turn

Look at the first few lines while you build.

sort app.log |  -n 3

The trap

head at the FRONT of a pipeline is a sample; at the END it is the top of an answer. They are different things and both are useful.

Practise build a pipeline one stage at a time on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.