1

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

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.