Lessons · Terminal · get it right on a thousand lines
Get it right on a thousand lines
Shape questions -- the delimiter, the columns, the casing, the header -- have shape answers, and shape does not need volume.
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
Being wrong on a sample costs a second. Being wrong on the whole file costs a minute and your attention.
How to think about it
head the file into a sample, build against that, then point the finished pipeline at the real thing once.
Worked example
head -n 3 access.log > sample.logA sample to work against.
cut -d' ' -f2 sample.log | sort | uniq -cThe shape is right.
cut -d' ' -f2 access.log | sort | uniq -cThe same pipeline, the whole file, once.
Your turn
Take the first thousand lines into a sample.
-n 1000 app.log > sample.log
Try it at a real prompt
The trap
A sample cannot tell you whether a rare, differently-shaped line exists further down -- and that is the line that breaks a pipeline.
Practise get it right on a thousand lines on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.