Hone

Lessons · Terminal · cut's delimiter is a tab

The delimiter you did not name

cut's default delimiter is a TAB. A line with no delimiter in it comes through whole rather than empty.

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

Together those two rules make the commonest cut failure look like success.

How to think about it

Always write -d. It costs three characters.

Worked example

cut -f2 tabbed.tsv
Works: this file really is tab-separated.
cut -f2 sales.csv
The whole line back. No tabs, so nothing split, so cut handed the line over untouched.
cut -d, -f2 sales.csv
Naming the delimiter fixes it.

Your turn

Tell cut that orders.csv is separated by commas.

cut , -f2 orders.csv

The trap

A quoted comma is still a comma to cut. "Leeds, West Yorkshire" becomes two fields, and that is the point at which a pipeline is the wrong tool.

Practise cut's delimiter is a tab on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.