2

For example:

$ cut -d ' ' -f 2- <<< "example"
example

Why does cut lie to me telling me that “example” is the second delimeter and on. I want it to print "" since there is no second delimeter.

Note this does the right thing:

$ cut -d ' ' -f 2- <<< "example "

1 Answer 1

2

You need to use the -s option:

$ cut -d ' ' -sf 2- <<< "example"
$

By default, if a line has no delimiters, cut will print the entire line. -s turns this behavior off.

Not that your second example, does have a delimiter:

cut -d ' ' -f 2- <<< "example "

Because the line has a delimiter, cut does what you expect.

Documentation

This behavior is documented in man cut:

-f, --fields=LIST
select only these fields; also print any line that contains no delimiter character, unless the -s option is specified

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .