For example:

$ cut -d ' ' -f 2- <<< "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 "

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.


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 agree to our terms of service, privacy policy and cookie policy

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