cut

>Usage

cut (Remove Sections of Each Line) is a command used for removing specific sections of each line in a file or text stream. It’s great for extracting columns of data, like pulling specific fields from a CSV or tab-separated file.

>Synopsis

cut [options] [file...]

>Options

-f

-f (fields): Selects which fields to print based on the delimiter.

Example 2:

Dots

-zsh

> echo "apple orange banana" | cut -f1,3


apple banana

-d

-d (delimiter): Specifies the delimiter for separating fields.

Example 1:

Dots

-zsh

> echo "apple,orange,banana" | cut -d"," -f2


orange

-c

-c (characters): Cuts based on character positions

Example 3:

Dots

-zsh

> echo "apple" | cut -c1-3


app

-b

-b (bytes): Cuts based on byte positions.

Example 4:

Dots

-zsh

> echo "apple" | cut -b1-2


ap

-s

-s (suppressed): Suppresses lines that do not contain the delimiter. In the example below, lines without a comma are ignored.

Example 5:

Dots

-zsh

> echo -e "apple,orange\nbanana" | cut -d"," -s -f1


apple

-z

-z (zero-terminated): Treats the input as zero-terminated.

Example 6:

Dots

-zsh

> echo -e "apple\0orange\0banana" | cut -z -d"\0" -f2


orange

>Quiz

Progress: Question ? out of ?

Question Title

Page written by Andrea Benvegnù