`cut -d: -f5-` prints lines even if they have no colon

Assuming a file named "file" containing the lines:

foo:bar:baz:qux:quux
one:two:three:four:five:six:seven
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog

If we use the cut command with these options we get:

$ cut -d ":" -f 5- file
quux
five:six:seven
epsilon:zeta:eta:theta:iota:kappa:lambda:mu
the quick brown fox jumps over the lazy dog

In the last line the colon character wasn't found so normally it shouldn't have taken that line because we begin with the 5th field to the end of line.

Why is that so ?


Solution 1:

By default cut with the -f option prints any line that doesn't contain a delimiter character. Use -s if you don't want them:

$ cut -d ":" -f 5- -s file
quux
five:six:seven
epsilon:zeta:eta:theta:iota:kappa:lambda:mu