Hone

Lessons · Terminal · cut -d and -f

Taking one column

-d says what separates the fields, -f says which ones you want, and fields are counted from 1.

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

Most log questions are really questions about one column.

How to think about it

Name the delimiter every time, even when you think the default fits.

Worked example

cut -d, -f2 sales.csv
The city column.
cut -d, -f1,3 sales.csv
First and third: a comma-separated LIST.
cut -d, -f2- sales.csv
Field two onwards: an open-ended range.

Your turn

Take the second comma-separated column of orders.csv.

cut -d,  2 orders.csv

The trap

-f1-3 is a RANGE and -f1,3 is a list. One of them quietly includes the middle column.

Practise cut -d and -f on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.