cut

Pull chosen columns or character ranges out of lines

About

A small filter. It keeps only the fields, bytes or characters you name and drops the rest. It works on a fixed delimiter or on character positions, which suits simple, regular data.

Install it

Included with Termux

Run this inside Termux. If the package is already present, pkg will say so and do nothing.

Commands worth knowing

6 of the invocations you will actually reach for. Tap the copy button to put one on your clipboard.

cut -d: -f1 users.txt Split each line on a colon and keep only the first field.
cut -d, -f2,4 data.csv Keep the second and fourth comma-separated columns. The rest are dropped.
cut -c1-10 notes.txt Keep only the first ten characters of every line.
cut -f3 --complement report.txt Print everything except the third field.
cut -s -d: -f1 users.txt Skip lines with no delimiter at all. That avoids stray output.
cut --output-delimiter=" " -d: -f1,7 users.txt Rejoin the kept fields with a different separator.

Worked example

Run cut -d, -f2,4 data.csv and this is what you should see.

termux
$ cut -d, -f2,4 data.csv
price,qty
199,3
249,1

Developed by

GNU Project .